Ubuntu – Nginx – 502 bad gateway

nginxserver

I'm working through How To Serve Django Applications with uWSGI and Nginx on Ubuntu 16.04.

I have completed the tut and restarted both nginx and uwsgi. I notice that if I go to the IP of my server, I see my site (making me think that uwsgi is working properly). However if I go to www.mysite.com, I get the 502 error. My nginx config file in the /etc/nginx/sites-available is mysite contains:

server {
listen 80;
server_name mysite.com www.mysite.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    root /home/deploy/mysite;
}

location / {
    include         uwsgi_params;
    uwsgi_pass      unix:/run/uwsgi/mysite.sock;
}

What am I doing wrong?

$ systemctl status uwsgi
Failed to connect to bus: No such file or directory

I'm confused, I know I have been working on a number of uwsgi files and

$ sudo systemctl start uwsgi 

does not cause an error. Also the website is still being served at the IP address. I thought uwsgi was doing that.

$ netstat -a|grep uwsgi
unix  2      [ ACC ]     STREAM     LISTENING     2373238691 /run/uwsgi/mysite.sock

Best Answer

The 502 Bad Gateway error means server is not getting proper response from another server. In your case it is uWSGI server. It is either not running or stopped due to error.

Check the status of uWSGI server by using sudo systemctl status uwsgi.

Related Question