Flask + uWSGI + Nginx + Fedora 20 设置问题
我正在尝试通过uWSGI把一个Flask应用部署到Nginx上,操作系统是Fedora 20,但遇到了一些问题。
我有以下配置文件:
NGINX - 默认配置,做了以下修改:
location / { try_files $uri @yourapplication; }
location @yourapplication {
include uwsgi_params;
uwsgi_pass unix:/tmp/sjudson_app_uswgi.sock;
}
uWSGI:
[uwsgi]
socket = /tmp/%n.sock
wsgi-file = sjudson_app/sjudson_app.py
callable = sjudson
master = true
chmod-socket = 666
logto = /home/server/logs/uwsgi.log
首先,当我尝试运行:
uwsgi --ini sjudson_app_uwsgi.ini
我只得到:
[uWSGI] getting INI configuration from sjudson_app_uwsgi.ini
一直停在那里。其次,当我直接从命令行运行时:
uwsgi --socket /tmp/sjudson_app_uwsgi.sock --wsgi-file sjudson_app/sjudson_app.py --callable sjudson --master --chmod-socket=666
我得到:
*** Starting uWSGI 2.0.3 (32bit) on [Tue Mar 25 17:58:44 2014] ***
compiled with version: 4.8.2 20131212 (Red Hat 4.8.2-7) on 25 March 2014 16:48:01
os: Linux-3.13.6-200.fc20.i686+PAE #1 SMP Fri Mar 7 17:17:53 UTC 2014
nodename: new-host-6
machine: i686
clock source: unix
detected number of CPU cores: 2
current working directory: /home/server
detected binary path: /usr/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 1024
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/sjudson_app_uwsgi.sock fd 3
Python version: 2.7.5 (default, Feb 19 2014, 13:47:40) [GCC 4.8.2 20131212 (Red Hat 4.8.2-7)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x881cc40
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 127952 bytes (124 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x881cc40 pid: 1131 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1131)
spawned uWSGI worker 1 (pid: 1136, cores: 1)
但是当我尝试连接到服务器时,出现了502错误。我注意到这个StackOverflow的帖子:Flask, nginx, and uwsgi,里面有类似的问题,得到的高票回答提到socket权限不正确。不过,我确实有设置chmod-socket=666这个参数,并且查看了/tmp目录:
srw-rw-rw-. 1 server server 0 Mar 25 17:53 sjudson_app_uwsgi.sock
所以我觉得这不是问题所在。
编辑:
我意识到我忘了包含Nginx的错误信息:
2014/03/26 07:58:38 [crit] 792#0: *15 connect() to unix:/tmp/sjudson_app_uswgi.sock
failed (2: No such file or directory) while connecting to upstream, client:
173.79.242.54, server: localhost, request: "GET / HTTP/1.1", upstream:
"uwsgi://unix:/tmp/sjudson_app_uswgi.sock:", host: "173.79.242.54"
我不太明白这里的“没有这样的文件或目录”是什么意思。我知道.sock文件是存在的,那它到底在找什么呢?
2 个回答
0
请把nginx配置中的字符串改一下,从
uwsgi_pass unix:/tmp/sjudson_app_uswgi.sock;
改成
uwsgi_pass unix:///tmp/sjudson_app_uswgi.sock;
2
我遇到了几乎完全相同的设置和错误信息。为了解决这个问题,我做了以下几件事:
在我的
uwsgi.ini
文件中,把 socket 的设置改成:socket = 127.0.0.1:8081
在我的
nginx.conf
文件中(在 server 语句外面)添加以下内容:upstream uwsgi { server 127.0.0.1:8081; }
在我的
nginx.conf
文件中,把 location 的设置改成:location / { try_files $uri @uwsgi; } location @uwsgi { include uwsgi_params; uwsgi_pass uwsgi; }
这样就让 nginx 和 uwsgi 能够正常沟通了。这些步骤是从 http://blog.djcentric.com/setting-up-uswgi-nginx-what-you-need-to-know/ 上找到的。