我试图使用带有nginx和uWSGI的ubuntu 12.04服务器来运行Flask应用程序但是在启动服务器之后,指定wsgi.ini文件然后启动nginx,我尝试访问该页面但是我得到了一个与nginx 502错误的网关错误。我知道这是烧瓶应用程序和uWSGI的问题。我检查了uWSGI日志,发现了这个:
*** Starting uWSGI 2.0.11.1 (64bit) on [Thu Sep 17 19:38:03 2015] ***
compiled with version: 4.8.4 on 17 September 2015 15:58:04
os: Linux-3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015
nodename: ip-172-31-30-153
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ubuntu/myapp
writing pidfile to /home/ubuntu/myapp/myapp.pid
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7862
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 TCP address 127.0.0.1:5000 fd 3
Python version: 2.7.6 (default, Jun 22 2015, 18:01:27) [GCC 4.8.2]
Set PythonHome to /home/ubuntu/myapp
ImportError: No module named site
我找到了this个问题的最佳答案,但看到了同样的错误。如果它与PYTHONHOME有关,我跟随this guide并声明:
$ PYTHONPATH变量似乎随机取消,并导致 后续步骤的错误。要避免这种情况,请将以下行添加到 〜/ .bashrc文件的顶部:
出口 PYTHONPATH =' /usr/lib/python2.7:/usr/lib/python2.7/plat-x86_64-linux-gnu:/usr/lib/python2.7/lib-tk:/ usr / lib中/ python2.7 / lib目录岁:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages:/ usr / lib中/ python2.7 / DIST-包/ PILcompat'
那么问题可能是什么?它是PYTHONHOME还是影响它的另一个因素?感谢。
修改
我的uwsgi.ini:
[uwsgi]
home = /home/ubuntu/myapp
wsgi-file = %(home)/run.py
socket = 127.0.0.1:5000
callable = app
module = app
pythonpath = %(home)
daemonize = %(home)/myapp.log
pidfile = %(home)/myapp.pid
要运行它,我使用uwsgi uwsgi.ini
。