Flask app on uwsgi / nginx - unix socket file not created at boot

I am trying to use the Flask application on uwsgi / nginx.

This http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html as well as http://www.markjberger.com/flask-with-virtualenv-uwsgi-nginx/ , I could make a file wiki.ini ,

 [uwsgi] vhost = true socket = /tmp/flask_app.sock venv = /home/ubuntu/webapp/flask/hello/.env chdir = /home/ubuntu/webapp/flask/hello module = flaskapp callable = app chmod-socket = 666 

I checked that the wiki.ini file wiki.ini fine with uwsgi --ini wiki.ini .

Then I tried to run the Flask application at boot time.

In sudo update-rc.d uwsgi enable I can start the uwsgi service at boot time and copy the wiki.ini file to the /etc/uwsgi/apps-enabled directory.

This is the conf file for nginx.

 server { listen 80; server_name wiki.example.com; access_log /var/log/nginx/uwsgi_access.log; error_log /var/log/nginx/uwsgi_error.log; location / { try_files $uri @riki; } location @riki { include uwsgi_params; uwsgi_pass unix:/tmp/flask_app.sock; } error_page 404 /404.html; } 

However, when I rebooted my ubuntu server, the Flask application does not work. I checked the error log to find this error message.

 2015/11/07 17:48:17 [crit] 1055#0: *1 connect() to unix:/tmp/flask_app.sock failed (2: No such file or directory) while connecting to upstream, client: 68.203.30.28, server: wiki.example.com, 

I created the file /tmp/flask_app.sock and ran chown -R www-data:www-data /tmp/flask_app.sock to make the application work.

 > touch /tmp/flask_app.sock > sudo chown www-data:www-data /tmp/flask_app.sock > sudo service uwsgi restart > sudo service nginx restart 

However, I had another connection failure error.

 2015/11/07 17:50:38 [error] 1055#0: *4 connect() to unix:/tmp/flask_app.sock failed (111: Connection refused) while connecting to upstream, client: 68.203.30.28, server: wiki.example.com, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/flask_app.sock:", host: "wiki.example.com" 

What could be wrong? How to teach uwsgi to create a unix domain socket? Also, how to make the connection work? I am using ubuntu 14.04.

EDIT

Removing /tmp/flask_app.sock and running uwsgi --ini /etc/uwsgi/apps-enabled/wiki.ini makes the application work fine.

+4
source share
1 answer

The main problem seems to be related to the maintenance of uwsgi; it just doesn't work.

I found another way to start uwsgi at startup: upstart and uwsgi --emperor from http://uwsgi-docs.readthedocs.org/en/latest/Upstart.html and http://upstart.ubuntu.com

The process simply creates the flask.conf file in the /etc/init directory. uwsgi --emperor manages all ini files in the uwsgi directory.

 # simple uWSGI script # http://uwsgi-docs.readthedocs.org/en/latest/Upstart.html description "uwsgi tiny instance" start on runlevel [2345] stop on runlevel [06] respawn exec uwsgi --emperor /etc/uwsgi/apps-enabled 

I also had to sudo update-rc.d uwsgi disable so that the uwsgi service was disabled.

I also found this site http://flaviusim.com/blog/Deploying-Flask-with-nginx-uWSGI-and-Supervisor/ to call uswgi at startup, but I have not tested it.

+1
source

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


All Articles