1

我正在尝试在 debian 6 上使用 uwsgi + python2.7 + django + nginx。我使用以下命令安装了 uwsgi:pip2.7 install uwsgi所以它与 python 2.7 一起运行。我正在使用以下命令以皇帝模式运行 uwsgi:uwsgi --emperor /etc/uwsgi/vassals/ -d /var/log/uwsgi.log --pidfile /var/run/uwsgi.pid

vassals 文件夹目前仅包含一个应用程序。这是它的yaml文件:

uwsgi:
    socket: /home/uwsgi/uwsgi/uwsgi.sock
    virtualenv: /opt/myproj/virt
    pythonpath: /home/uwsgi/project/my_proj
    pidfile: /home/uwsgi/uwsgi/uwsgi.pid
    uid: uwsgi
    gid: uwsgi
    chmod-socket: 1
    module: wsgi_app
    daemonize:  /home/uwsgi/uwsgi/uwsgi.log
    harakiri-verbose: 1

这是 Django 项目文件的内容:

#! /usr/bin/python
SITE_DIR = '/home/uwsgi/project/my_proj'
import site
site.addsitedir(SITE_DIR)

import os
import sys
sys.path.append(SITE_DIR)

sys.path.append('/home/uwsgi/project/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'my_proj.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

现在,当我尝试启动它时,/home/uwsgi/uwsgi/uwsgi.log 文件中的结果如下:

*** Starting uWSGI 1.0.4 (32bit) on [Fri Mar  2 19:00:46 2012] ***
compiled with version: 4.6.2 on 02 March 2012 18:03:07
current working directory: /etc/uwsgi/vassals
writing pidfile to /home/uwsgi/uwsgi/uwsgi.pid
detected binary path: /usr/local/bin/uwsgi
setgid() to 1001
setuid() to 1001
your memory page size is 4096 bytes
chmod() socket to 666 for lazy and brave users
uwsgi socket 0 bound to UNIX address /home/uwsgi/uwsgi/uwsgi.sock fd 3
Python version: 2.7.2+ (default, Dec  1 2011, 02:17:49)  [GCC 4.6.2]
Set PythonHome to /opt/myproj/virt
ImportError: No module named site
*** Starting uWSGI 1.0.4 (32bit) on [Fri Mar  2 19:00:47 2012] ***
compiled with version: 4.6.2 on 02 March 2012 18:03:07
current working directory: /etc/uwsgi/vassals
writing pidfile to /home/uwsgi/uwsgi/uwsgi.pid
detected binary path: /usr/local/bin/uwsgi
setgid() to 1001
setuid() to 1001
your memory page size is 4096 bytes
chmod() socket to 666 for lazy and brave users
uwsgi socket 0 bound to UNIX address /home/uwsgi/uwsgi/uwsgi.sock fd 3
Python version: 2.7.2+ (default, Dec  1 2011, 02:17:49)  [GCC 4.6.2]
Set PythonHome to /opt/myproj/virt
ImportError: No module named site

如您所见,uwsgi 无法导入站点模块,因此 uwsgi 不断尝试重新启动应用程序。所以我尝试在 yaml 文件中添加 no-site :1 选项。结果是我无法在我的 Django 项目文件中导入任何内容...

我也知道它没有链接到项目,因为如果我用 python 2.6 运行 uwsgi,它就可以正常工作......不幸的是,我必须用 python2.7 运行它......

你知道会发生什么吗?

非常感谢!

4

1 回答 1

3

确保你的 virtualenv 是为 python2.7 构建的,否则无法使用。

它必须包含 /opt/myproj/virt/lib/python2.7 目录

于 2012-03-02T18:26:25.400 回答