How can I make my nextjs with Express site work on ssl
You probably want to use Apache for all the SSL handling and listen to the 443
port, then proxy to your 3007
port. Try this config:
<VirtualHost *:443> ProxyPreserveHost On ProxyRequests Off ServerName myreactsite.com ServerAlias myreactsite.com ProxyPass / http://0.0.0.0:3007/ ProxyPassReverse / http://0.0.0.0:3007/ SSLEngine On SSLProxyEngine On SSLCertificateFile /home/myreactsite.crt SSLCertificateKeyFile /home/myreactsite.key</VirtualHost>
To redirect all HTTP traffic then:
<VirtualHost *:80> ServerName myreactsite.com Redirect / https://myreactsite.com/ </VirtualHost>
Based on @fabian comment, I am posting my working configurations if it helps someone...
Added the following lines in the 443 virtual host section for the site in apache.conf :
ProxyPreserveHost OnProxyRequests Off<Proxy *> Order deny,allow Allow from all</Proxy>ProxyPass / http://example.com:3000/ProxyPassReverse / http://example.com:3000/SSLProxyEngine On#To redirect to https and www versionRewriteEngine OnRewriteCond %{HTTP_HOST} ^example\.com$ [NC]RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
Also, added the following line in the nginx vhost file for the site :
server { ... ...#To redirect all http requests to https+wwwreturn 301 https://www.example.com$request_uri; ... ...}