By dgolant
I have the following Nginx config:
# HTTP redirect all traffic to HTTPS
server {
listen 80 default_server;
listen [::]:80 default_server;
# server_name linkmelater.win;
if ($scheme = "http") { # Only redirect if not using SSL
# return 301 https://$server_name$request_uri;
return 302 https://$host$request_uri;
}
}
# HTTPS — proxy all requests to the Node app
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name linkmelater.win;
# Use the Let’s Encrypt certificates
ssl_certificate /etc/letsencrypt/live/linkmelater.win/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/linkmelater.win/privkey.pem;
# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:5000;
# proxy_pass http://0.0.0.0:5000;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
And a Docker container that I run using docker run -p 5000:5000 -d -e NODE_ENV=production containername:tagname
The container is running properly and the Node server listens on 5000 like so:
if (process.env.NODE_ENV === 'production') {
server = app.listen(process.env.PORT || 9145, function () {
logger.info('Production Server listening on port ' + process.env.PORT || 9145);
process.env.DOMAIN = '0.0.0.0:' + process.env.PORT;
});
}
For some reason when I go to https://www.linkmelater.win I get ERR_TOO_MANY_REDIRECTS and when I navigate to the IP and Port directly (https://67.205.153.198:5000/) I get ERR_CONNECTION_CLOSED. This was all working before I added the Nginx layer (for SSL/RP) and it all works locally where I don’t run the Nginx server and just access localhost:5000 directly.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.