I'm trying to use Flask app on uwsgi/nginx.
Following http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html and http://www.markjberger.com/flask-with-virtualenv-uwsgi-nginx/, I could make wiki.ini
file,
[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 the wiki.ini
file works fine with uwsgi --ini wiki.ini
.
Then, I tried to start the Flask app when booting.
From sudo update-rc.d uwsgi enable
, I could start the uwsgi service in booting time, and copied the wiki.ini file in /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 app isn't working. 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 /tmp/flask_app.sock
file and run chown -R www-data:www-data /tmp/flask_app.sock
to make the application working.
> 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 refuse 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 might be wrong? How to teach uwsgi to create the unix domain socket? Also, how to make the connection work? I use ubuntu 14.04.
EDIT
Removing the /tmp/flask_app.sock
and run uwsgi --ini /etc/uwsgi/apps-enabled/wiki.ini
makes the app working fine.