Configuring nginx server on python flask application

I am new to server setup. And I want to set up an instance of Amazon-EC2. I configured it according to this document. http://www.soundrenalin.com/about

However, when I click the URL, I get a 502 Bad Gateway error. My project is on this path: /home/ubuntu/dsn/app .
And the folder tree /home/ubuntu/dsn :

 app/ app.py static/ templates/ themes/ bin/ build/ include/ lib/ local/ run.py 


Here is my configuration nginx could ( /etc/nginx/sites-available/default ):

 server { listen 80; root /home/ubuntu/dsn/app index index.html index.htm; server_name localhost; location / { try_files $uri @app; } location @app { include uwsgi_params; uwsgi_pass unix:/tmp/uwsgi.sock; } } 

And here is my uwsgi.ini file:

 [uwsgi] chdir = /home/ubuntu/dsn/ uid = www-data gid = www-data chmod-socket = 666 socket = /tmp/uwsgi.sock module = run virtualenv = /home/ubuntu/dsn/ 

And other:
When I run the tail -f /var/log/nginx/error.log command, the result is:

 2013/06/09 15:58:11 [error] 5321#0: *1 connect() to unix:/tmp/uwsgi.sock failed (111: Connection refused) while connecting to upstream, client: <myip>, server: localhost, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/uwsgi.sock:", host: "54.218.14.213" 

How can i solve this? Thank you

+3
source share
2 answers

It could be one of the following things:

  • Your UWSGI socket is not located at /tmp/uwsgi.sock
  • The user uwsgi or www-data does not have permission to create uwsgi.sock in the / tmp directory.

If you installed Uwsgi on Ubuntu 12.04, the configuration file should be located at:

 /usr/share/uwsgi/conf/default.ini 

Here's the default socket configuration in this file:

 # bind to UNIX socket at /run/uwsgi/<confnamespace>/<confname>/socket socket = /run/uwsgi/%(deb-confnamespace)/%(deb-confname)/socket 

You should create an application configuration file similar to mine. I can confirm that it works in a virtual environment.

 sudo vim /etc/uwsgi/apps-available/your-app.ini 

The contents of your app.ini application:

 [uwsgi] base = /home/nick/your-app.com #location of the flask application file file = /home/nick/your-app.com/main.py #uwsgi varible only, does not relate to your flask application callable = app #uwsgi plugins plugins = http,python #to create within a virtual environment home = %(base)/venv pythonpath = %(base) socket = /tmp/%n.sock logto = /var/log/uwsgi/%n.log workers = 3 

To enable, you need to symbolically and restart nginx.

 #make sure that any user to write to the /tmp directory sudo chmod 777 /tmp sudo ln -s /etc/uwsgi/apps-available/your-app.ini /etc/uwsgi/apps-enabled/your-app.ini sudo service uwsgi restart 
+1
source

From fooobar.com/questions/1262871 / ...

You can use uubutu upstart, and uwsgi --emperor is the ability to easily run uwsgi python applications.

-2
source

Source: https://habr.com/ru/post/1262863/


All Articles