How to Fix Nginx 502: Bad Gateway Error on a Digital Ocean Droplet - Ubuntu 20.04

502 Bad Gateway, I messed up users and groups permissions on digitalocean ubuntu for django deployment

I guess that the problem is that by running sudo chmod -R 760 /var/www/ you have forbidden non-ownesrs of the folder to read, write and execute files form that directory. Then, since uwsgi processes does not belong to the www-data group (usually), uwsgi connection was refused.

The easiest way to solve this problem is to run sudo chmod -R 766 /var/www/ - this will grant writing and readind priveleges to anyone (chmod -R 764 should also work and is safer - it allows only reading files for non-owners). Alternatively, you may find out the name of the user running uwsgi and grant him permissions for reading files form the directory. See chmod manual (or google it) for reference.

Unable to access my website using the IP address of my Digital Ocean droplet

You are missing the Nginx. Port 80 is open but you are trying 5000, so won't work.

You can open port 5000 in the firewall and also check ufw firewall.

ufw status 

and open the port using command

sudo ufw allow 5000

After setting up server blocks, Nginx is not serving my domain name

1. chmod 777 is NEVER a good idea.

NGINX operats under a runuser. How to check the runuser:

ps -elf |grep nginx. Normaly it will be nginx. Instead of 777 (Open for everyone) do chmod -R 755 /path/to/folder and chown -R nginx:nginx /path/to/folder

But agree. For troubleshooting it can be used. But back to your problem.

2. Directory-Listing disabled.

The error is telling you nginx can not list the directory content. Which is the default behavior. Make sure

root /var/www/sundaray.io/html;

This path exists AND

index index.html index.htm index.nginx-debian.html;

there are one of these files located!

Without any of these files NGINX can't load the default index file on /. Put something in /var/www/sundaray.io/html like

printf "<html>\n<body>\n<h1>Hello from NGINX</h1>\n</body>\n</html>" > /var/www/sundaray.io/html/index.html && chown nginx:nginx /var/www/sundaray.io/html/index.html. This should generate an index.html for you.

If you just want to test your server configuration without any files:

location / {
return 200 "Hello on $host$uri\n";
}

Why, I can't update my react app hosted on Digital Ocean?

Have you tried to clean the cache from your local browser?

If you do not want to clean local browser cache, open a new browser in incognito mode.

For debugging without risk of cache local, i would recommend open a browser in developer console (F12), change to tab network and click button disable cache.

Sample Image

The disable cache option is only active if developer console is open.

502 Bad Gateway when installing PHP7.2 on nginx

I had same problem, so I changed the nginx config file /etc/nginx/sites-avaiable/your-site.

Change:

fastcgi_pass unix:/run/php/php7.1-fpm.sock;

to

fastcgi_pass unix:/run/php/php7.2-fpm.sock;

This worked for me.

PM2 and Nginx: 502 Bad Gateway

I just had to start PM2 with bin/www instead of app.js. Express generator and everything...



Related Topics



Leave a reply



Submit