How To Serve Flask Applications with Gunicorn and Nginx on Ubuntu 20.04

Posted February 21, 2021 840 views
NginxUbuntuPythonPython FrameworksUbuntu 20.04


Followed the tutorial on Flask/Gunicorn/Nginx/Ubuntu20.04 and am having a problem at the point where Nginx connects to the myproject.socket file. Client request results in an error in /var/log/nginx/error that reports ‘Permission denied’:

*3 connect() to unix:/home/user/myproject/myproject.sock failed (13: Permission denied) while connecting to upstream, client: …, server: … , request: “GET / HTTP/1.1”, upstream: “http://unix:/home/user/myproject/myproject.sock:/”, host: “…”

Have tried 777 permissions on the socket file and changes to the permission on the parent dir with no success. Any ideas? Could it be an issue with the www-data user’s memberships?


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

I have the exact same problem. So assuming your DNS settings are okay, the solution is simple: Set up based on but as a User and not as root. :)

by Kathleen Juell
by Jamon Camisso
In this guide, you will build a Python application using the Flask microframework on Ubuntu 20.04. The majority of this tutorial is about how to set up the Gunicorn application server to run the application and how to configure Nginx to act as a front-end reverse proxy.