Serving flask application with Nginx and gunicorn: permission denied when connecting to webpage.sock

Question:

I am trying to setup a simple flask application served by Nginx and Gunicorn and have mostly followed this tutorial. When trying to access the webpage, I get a 502 Bad Gateway error.

The nginx log (/var/log/nginx/error.log) says :

[crit] 23472#0: *1 connect() to unix:/home/crawforc3/webpage/webpage.sock failed (13: Permission denied)

I checked and there is a webpage.sock file in my project directory that looks like this:

srwxrwxrwx 1 crawforc3 www-data 0 May 31 17:59 webpage.sock

Here is my /etc/systemd/system/gunicorn.service

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=crawforc3
Group=www-data
WorkingDirectory=/home/crawforc3/webpage
Environment="PATH=home/crawforc3/miniconda3/envs/HALSWEBPAGE/bin"
ExecStart=/home/crawforc3/miniconda3/envs/HALSWEBPAGE/bin/gunicorn --workers 3 --bind unix:/home/crawforc3/webpage/webpage.sock -m 007 wsgi:app

[Install]
WantedBy=multi-user.target
Asked By: Chris

||

Answers:

I discovered that there was a discrepancy with /etc/nginx/nginx.conf

I had the user set as www-data and I should have set it as crawforc3. Making this change and restarting nginx and gunicorn resolved the issue.

Answered By: Chris

Thanks you so much. this solved my issue, I was struggling with this from la

Answered By: Sunil Gayakawad
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.