uwsgi/nginx 上的 Flask 应用程序 - 启动时未创建 unix 套接字文件
Flask app on uwsgi/nginx - unix socket file is not created on booting
我正在尝试在 uwsgi/nginx 上使用 Flask 应用程序。
关注
http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
和
http://www.markjberger.com/flask-with-virtualenv-uwsgi-nginx/,我可以制作 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
我检查了 wiki.ini
文件在 uwsgi --ini wiki.ini
下工作正常。
然后,我尝试在启动时启动 Flask 应用程序。
从sudo update-rc.d uwsgi enable
开始,我可以在开机时启动uwsgi服务,并复制/etc/uwsgi/apps-enabled
目录下的wiki.ini文件。
这是 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;
}
但是,当我重新启动 ubuntu 服务器时,Flask 应用程序无法运行。
我检查了错误日志以找到此错误消息。
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,
我创建了 /tmp/flask_app.sock
文件和 运行 chown -R www-data:www-data /tmp/flask_app.sock
以使应用程序运行。
> touch /tmp/flask_app.sock
> sudo chown www-data:www-data /tmp/flask_app.sock
> sudo service uwsgi restart
> sudo service nginx restart
但是,我遇到了另一个连接拒绝错误。
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"
可能出了什么问题?如何教 uwsgi 创建 unix 域套接字?另外,如何使连接工作?我使用 ubuntu 14.04.
编辑
删除 /tmp/flask_app.sock
和 运行 uwsgi --ini /etc/uwsgi/apps-enabled/wiki.ini
可使应用正常运行。
主要问题似乎出在uwsgi服务上;它就是行不通。
我找到了另一种在启动时启动 uwsgi 的方法:upstart 和 uwsgi --emperor
来自 http://uwsgi-docs.readthedocs.org/en/latest/Upstart.html and http://upstart.ubuntu.com
该过程只是在 /etc/init
目录中创建一个 flask.conf
文件。 uwsgi --emperor
控制uwsgi目录下的所有ini文件。
# 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
我还必须 sudo update-rc.d uwsgi disable
才能禁用 uwsgi 服务。
我也找到了这个站点 http://flaviusim.com/blog/Deploying-Flask-with-nginx-uWSGI-and-Supervisor/ 用于在启动时调用 uswgi,但我没有测试它。
我正在尝试在 uwsgi/nginx 上使用 Flask 应用程序。
关注
http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html
和
http://www.markjberger.com/flask-with-virtualenv-uwsgi-nginx/,我可以制作 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
我检查了 wiki.ini
文件在 uwsgi --ini wiki.ini
下工作正常。
然后,我尝试在启动时启动 Flask 应用程序。
从sudo update-rc.d uwsgi enable
开始,我可以在开机时启动uwsgi服务,并复制/etc/uwsgi/apps-enabled
目录下的wiki.ini文件。
这是 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;
}
但是,当我重新启动 ubuntu 服务器时,Flask 应用程序无法运行。 我检查了错误日志以找到此错误消息。
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,
我创建了 /tmp/flask_app.sock
文件和 运行 chown -R www-data:www-data /tmp/flask_app.sock
以使应用程序运行。
> touch /tmp/flask_app.sock
> sudo chown www-data:www-data /tmp/flask_app.sock
> sudo service uwsgi restart
> sudo service nginx restart
但是,我遇到了另一个连接拒绝错误。
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"
可能出了什么问题?如何教 uwsgi 创建 unix 域套接字?另外,如何使连接工作?我使用 ubuntu 14.04.
编辑
删除 /tmp/flask_app.sock
和 运行 uwsgi --ini /etc/uwsgi/apps-enabled/wiki.ini
可使应用正常运行。
主要问题似乎出在uwsgi服务上;它就是行不通。
我找到了另一种在启动时启动 uwsgi 的方法:upstart 和 uwsgi --emperor
来自 http://uwsgi-docs.readthedocs.org/en/latest/Upstart.html and http://upstart.ubuntu.com
该过程只是在 /etc/init
目录中创建一个 flask.conf
文件。 uwsgi --emperor
控制uwsgi目录下的所有ini文件。
# 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
我还必须 sudo update-rc.d uwsgi disable
才能禁用 uwsgi 服务。
我也找到了这个站点 http://flaviusim.com/blog/Deploying-Flask-with-nginx-uWSGI-and-Supervisor/ 用于在启动时调用 uswgi,但我没有测试它。