Skip to content Skip to sidebar Skip to footer

Nginx + Gunicorn + Flask - 502 Bad Gateway - Permission Denied On Socket File

We are trying to set up NGINX as a reverse proxy to our Gunicorn Python application. We have been following this Guide from Digital Ocean (https://www.digitalocean.com/community/tu

Solution 1:

I just ran into this problem. I was able to create the gunicorn socket file, but nginx complained about permission denied. The issue was that my socket file was in a sub-folder and the root folder did not have read or execute permissions. So even though the sub-folder had the correct permissions, the root folder prevented nginx from entering the sub-folder.

The solution was to add read and execute permissions to the root folder:

chmod o+rx /example_root_folder

Solution 2:

Instead of entering app.com in the server name, try entering the IP address of the host machine and see if that works on the machine itself by running:

$curl <IP address of the host machine>

If still it doesn't work, I have written an article on the same, try to implement it using that and let me know if it works!

Hope it helps! :)

Solution 3:

We were able to resolve this by giving the www-data group access to the full application folder: sudo chgrp www-data ~/app. It already had access to the socket file specifically, but not the application folder.

I didn't think this was necessary since we specified the root user as the owner of the service. The root user already had access to the app folder and the instructions we were following didn't have steps for setting up the group access.

I don't have a lot of experience with Linux permissions/ownership though so this might be obvious to most experienced users.

Post a Comment for "Nginx + Gunicorn + Flask - 502 Bad Gateway - Permission Denied On Socket File"