【问题标题】:Configure uWSGI to use virtualenv配置 uWSGI 以使用 virtualenv
【发布时间】:2013-06-15 11:42:44
【问题描述】:

我已经通过apt-get 安装了 uWSGI 和 nginx,并将我的 uwsgi-conf.ini 放在 /etc/uwsgi/apps-available 中并将其符号链接到启用应用程序,并按照相同的过程进行 nginx 配置。

(下面列出的配置文件)

问题是我无法让 uWSGI 启动位于 /usr/share/nginx/www/helloflask/venv 中的 virtualenv

如果我添加行 virtualenv = /usr/share/nginx/www/helloflask/venv 并访问服务器,我会收到 502 Bad Gateway 错误?

如果没有.ini 文件中的virtualenv 行,我会收到以下消息:

uWSGI Error

Python application not found

以下是日志文件中的几行:

Traceback (most recent call last):
  File "/usr/share/nginx/www/helloflask/test.py", line 1, in <module>
    from application import app
  File "/usr/share/nginx/www/helloflask/application.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask
 - unable to load app 0 (mountpoint='xx.xx.xxx.xx|') (callable not found or import error)
xx.xx.xxx.xx {address space usage: 134094848 bytes/127MB} {rss usage: 12623872 bytes/12MB} [pid: 29848|app: -1|req: -1/6] 95.166.70.107 () {44 vars in 721 bytes} [Thu May  9 08:40:29 2013] GET /favicon.ico => generated 48 bytes in 5 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0)

/etc/uwsgi/apps-available/uwsgi-conf.ini

[uwsgi]
plugins = python
gid = nginx
uid = nginx
vhost = true
logdate
socket = 127.0.0.1:3031
master = true
processes = 1
harakiri = 20
limit-as = 128
memory-report
no-orphans = true

/etc/nginx/sites-available/helloflask

server {
  listen 80;
  server_name xx.xx.xxx.xxx;
  location / {
    include uwsgi_params;
    uwsgi_param UWSGI_CHDIR /usr/share/nginx/www/helloflask/;
    uwsgi_param UWSGI_PYHOME /user/share/nginx/www/helloflask/;
    uwsgi_param UWSGI_SCRIPT test;
    uwsgi_pass 127.0.0.1:3031;
  }
}

【问题讨论】:

    标签: nginx flask virtualenv uwsgi


    【解决方案1】:

    很明显,您的 virtualenv 中缺少必需的模块,通过以下输出:

    ImportError: No module named flask
    

    尝试将flask模块安装到你的virtualenv中,如果需要,也安装任何其他需要的模块。

    source /usr/share/nginx/www/helloflask/venv/bin/activate
    pip install flask
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-17
      • 2013-08-27
      • 2015-05-03
      • 2014-04-07
      • 2016-10-13
      • 1970-01-01
      • 2016-05-01
      相关资源
      最近更新 更多