Hi all,
Followed this tutorial to get Let’s Encrypt working on my Nest.js/Node server.
Everything works - running sudo nginx -t
returns:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
However, accessing my domain gives me a 502 Bad Gateway error. Specifically (from /var/log/nginx
):
15004#15004: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 77.98.141.183, server: ww2.zone, request: "GET / HTTP/2.0", upstream: "http://127.0.0.1:8000/", host: "ww2.zone"
Here is my /etc/nginx/sites-available
file:
Default server configuration
server {
listen 80;
listen 127.0.01;
listen [::]:80 default_server ipv6only=on;
return 301 https://$host$request_uri;
}
server {
# Enable HTTP/2
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ww2.zone;
# Use the Let’s Encrypt certificates
ssl_certificate /etc/letsencrypt/live/ww2.zone/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ww2.zone/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:8000/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
And my server is within a git Repo within home/username
.
The code to listen on the port is:
await app.listen(process.env.PORT || 5000);
This used to be process.env.PORT || 80
but that would throw:
Error: listen EADDRINUSE: address already in use :::80
Any ideas? Pulling my hair out atm.
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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hello,
You can only have 1 service listening on 1 port. So as you have Nginx listening on port 80 at the moment, you can not have your Node on the same port.
Also as you currently have your Nginx set to work as a reverse proxy for port 8000, what you could do is to just set Node to listen on port 8000.
This would fix your 502 error.
Here is a link to an answer on how to troubleshoot common Nginx problems:
https://www.digitalocean.com/community/questions/how-to-troubleshoot-common-nginx-issues-on-linux-server
Here is also a quick video demo on how to do that:
Hope that this helps! Regards, Bobby
I have the same problem.
I get the errors (I change the name of my ip to the word server for security reasons):
The service is running on port 5000 with the command
netstat -plant
nginx.conf
Hello, looks like I am also facing the same issue. And this has suddenly come up. Haven’t done any changes to server unless DO has done at their end.
Kindly help. The error fron nginx/error.log:
2020/10/12 11:05:44 [error] 915#915: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 122.177.172.254, server: test.uxhack.co, request: “GET /favicon.ico HTTP/1.1”, upstream: “http://127.0.0.1:8000/favicon.ico”, host: “test.uxhack.co”, referrer: “https://test.uxhack.co/” 2020/10/12 11:08:07 [error] 915#915: *4 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 122.177.172.254, server: test.uxhack.co, request: “GET / HTTP/1.1”, upstream: “http://127.0.0.1:8000/”, host: “test.uxhack.co” 2020/10/12 11:08:07 [error] 915#915: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 122.177.172.254, server: test.uxhack.co, request: “GET /favicon.ico HTTP/1.1”, upstream: “http://127.0.0.1:8000/favicon.ico”, host: “test.uxhack.co”, referrer: “https://test.uxhack.co/”
Kindly help