I have an nginx server that’s giving me an error that I can’t find any information on. The server is up and running and I believe the underlying site (a Flask app) is also running, but clients receive a generic 500 error. When I look at /var/log/nginx/error.log
, I see this:
2022/09/04 04:59:52 [error] 1523#1523: *1 connect() failed (111: Unknown error) while connecting to upstream, client: [clients ip], server: mysite.com, request: "GET / HTTP/1.1", upstream: "http://[::1]:8000/", host: "mysite.com"
I have no idea what to do with this. I’ve searched around and can’t find any info on how to dig in deeper or where to look to resolve the issue.
How I got into this state
I’m running the server on Ubuntu on a Linode and wanted to upgrade the OS. To do so, I spun up a new Linode with the latest version of Ubuntu (22.04) and recreated the server from scratch. After getting everything installed, I swapped the IP addresses of the old and new servers to avoid having to redo the DNS records. I’m using CertBot to manage https certificates, so I ran that again and then restarted everything.
At this point, nginx was up and running and happy with my config. Everything looks the same as it did on the old server. But every request is a 500 with the error above.
Any help / pointers to get me back to a working state is very much appreciated!
EDIT: nginx config
server {
server_name = www.mysite.com;
return 301 $scheme://mysite.com$request_uri;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
server_name mysite.com;
location ^~ /static/ {
include /etc/nginx/mime.types;
root /home/my_username/path/to/code/;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
proxy_read_timeout 300s;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mysite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.mysite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mysite.com) {
return 301 https://$host$request_uri;
} # Manually added by me
server_name = mysite.com;
listen 80;
return 404; # managed by Certbot
}
2
Answers
Ugh. I was a dummy. It was not an nginx error.
I misconfigured something in my Flask site, causing it to throw 500 errors. Because of the misconfiguration, they weren't being logged to the right file, so I didn't realize that was the problem. Fixed the Flask config and the server went back to normal.
Posting my stupidity in case it helps any future searchers who hit the same nginx error.
Rewrite your nginx config to use ip, not dns. For instance, 127.0.0.1 instead of localhost, or remove the ipv6 alias from /etc/hosts.
Try this.