I have tried looking for an answer, but mostly people get this error with uwsgi not Gunicorn.

nginx error log has the following output:

2019/09/20 17:23:20 [crit] 28847#28847: *2 connect() to unix:/home/ubuntu/app_test/app_test.sock failed (13: Permission denied) while connecting to upstream, client: <client-ip>, server: <server-ip>, request: "GET / HTTP/1.1", upstream: "http://unix:/home/ubuntu/app_test/app_test.sock:/", host: "<ip-address>"

I have the following configuration file for the app in nginx's sites-available directory with a simlink to in sites-enabled:

server {
    listen 80;
    server_name <server-ip>;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/ubuntu/app_test/app_test.sock;

This is the service file in /etc/systemd/system/app_test.service

Description=Gunicorn instance to serve app_test

ExecStart=/home/ubuntu/app_test/appenv/bin/gunicorn --workers 3 --bind unix:app_test.sock -m 002 wsgi:app


(By the way, I have tried the socket file with a mask of 007 as well, just to be sure. Still the same response in the log after restarting both service and nginx.)

This is the app_test.pyfile:

from flask import Flask
app = Flask(__name__)

def hello():
    return "<h1 style='color:blue'>Hello There!</h1>"

if __name__ == "__main__":

Finally, this is wsgi.py:

from app_test import app

if __name__ == "__main__":

The error was within the Gunicorn service file. Since nginx was configured to run in the www-data group, it didn't have access to the app_test.sock file. I changed the group setting to www-data and it's working great now!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.