uwsgi/nginx上的Flask应用程序-引导时未创建unix套接字文件 [英] Flask app on uwsgi/nginx - unix socket file is not created on booting

查看:126
本文介绍了uwsgi/nginx上的Flask应用程序-引导时未创建unix套接字文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在uwsgi/nginx上使用Flask应用程序.

I'm trying to use Flask app on uwsgi/nginx.

以下 http://uwsgi-docs.readthedocs.org/en/latest/tutorials /Django_and_nginx.html http://www.markjberger.com/flask-with-virtualenv-uwsgi- nginx/,我可以制作wiki.ini文件

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

我检查了wiki.ini文件能否与uwsgi --ini wiki.ini正常工作.

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

然后,我尝试在启动时启动Flask应用.

Then, I tried to start the Flask app when booting.

sudo update-rc.d uwsgi enable中,我可以在启动时启动uwsgi服务,然后将wiki.ini文件复制到/etc/uwsgi/apps-enabled目录中.

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.

这是nginx的conf文件.

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;
}

但是,当我重新启动ubuntu服务器时,Flask应用程序无法正常工作. 我检查了错误日志以找到此错误消息.

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,

我创建了/tmp/flask_app.sock文件并运行chown -R www-data:www-data /tmp/flask_app.sock以使应用程序正常运行.

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"

可能是什么问题?如何教uwsgi创建Unix域套接字?另外,如何使连接正常工作?我使用的是Ubuntu 14.04.

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.

删除/tmp/flask_app.sock并运行uwsgi --ini /etc/uwsgi/apps-enabled/wiki.ini可使应用正常运行.

Removing the /tmp/flask_app.sock and run uwsgi --ini /etc/uwsgi/apps-enabled/wiki.ini makes the app working fine.

推荐答案

主要问题似乎来自uwsgi服务.只是不起作用.

The main issue seems to be from the uwsgi service; it just doesn't work.

我发现了另一种在启动时启动uwsgi的方法:upstart和uwsgi --emperor http://uwsgi-docs.readthedocs.org/en/latest/Upstart.html http://upstart .ubuntu.com

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

该过程只是在/etc/init目录中创建一个flask.conf文件. uwsgi --emperor控制uwsgi目录中的所有ini文件.

The process is just make a flask.conf file in /etc/init directory. uwsgi --emperor controls all the 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

我还必须sudo update-rc.d uwsgi disable以便应禁用uwsgi服务.

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

我还找到了该站点 http://flaviusim. com/blog/Deploying-Flask-with-nginx-uWSGI-and-Supervisor/用于在启动时调用uswgi,但我没有对其进行测试.

I also found this site http://flaviusim.com/blog/Deploying-Flask-with-nginx-uWSGI-and-Supervisor/ for invoking uswgi at startup, but I didn't test it.

这篇关于uwsgi/nginx上的Flask应用程序-引导时未创建unix套接字文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆