2

所以我有以下配置:

  • 带有 uWsgi 的 Nginx 服务器
  • virtualenv 中的 Django 项目

我的 virtualenv 由一个序数系统用户拥有,整个配置工作正常!uwsgi 进程配置为使用 nginx uid & gid 以及 nginx.conf 中的 nginx 进程所有者运行。

但是,如果我尝试使用另一个满足相同要求但由 root 拥有的 virtualenv,我的 uwsgi 无法找到该 virtualenv,从而引发导入错误。

这是正常的吗?我使用 root 拥有的 virtualenv 的方法是否正确?

编辑:

  • uwsgi 配置:

    [uwsgi]
    virtualenv = /root/Envs/rootenv
    thread = 4
    uid = nginx
    gid = nginx
    env = DJANGO_SETTINGS_MODULE=myServer.settings
    module = django.core.handlers.wsgi:WSGIHandler()
    chdir = /var/www/myServer
    socket = /var/run/uwsgi/myserver.sock
    logto = /var/log/uwsgi/myserver.log
    
  • /root/.bashrc:

    ### Virtualenv settings ###
    export WORKON_HOME=/root/Envs
    source /usr/local/bin/virtualenvwrapper.sh
    export PIP_VIRTUALENV_BASE=$WORKON_HOME
    export PIP_RESPECT_VIRTUALENV=true
    
  • uwsgi 日志回溯:

    *** Starting uWSGI 1.9.15 (64bit) on [Fri Sep  6 14:02:41 2013] ***
    compiled with version: 4.7.2 on 06 September 2013 10:59:26
    os: Linux-3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2
    nodename: myserver3
    machine: x86_64
    clock source: unix
    pcre jit disabled
    detected number of CPU cores: 2
    current working directory: /
    detected binary path: /usr/local/bin/uwsgi
    setgid() to 32
    set additional group 4 (adm)
    setuid() to 32
    *** WARNING: you are running uWSGI without its master process manager ***
    your processes number limit is 7929
    your memory page size is 4096 bytes
    detected max file descriptor number: 1024
    lock engine: pthread robust mutexes
    uwsgi socket 0 bound to UNIX address /var/run/uwsgi/myserver.sock fd 3
    Python version: 2.7.3 (default, Jan  2 2013, 14:09:21)  [GCC 4.7.2]
    Set PythonHome to /root/Envs/rootenv
    ImportError: No module named site
    *** Starting uWSGI 1.9.15 (64bit) on [Fri Sep  6 14:03:13 2013] ***
    compiled with version: 4.7.2 on 06 September 2013 10:59:26
    os: Linux-3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2
    nodename: myserver3
    machine: x86_64
    clock source: unix
    pcre jit disabled
    detected number of CPU cores: 2
    current working directory: /
    detected binary path: /usr/local/bin/uwsgi
    setgid() to 32
    set additional group 4 (adm)
    setuid() to 32
    *** WARNING: you are running uWSGI without its master process manager ***
    your processes number limit is 7929
    your memory page size is 4096 bytes
    detected max file descriptor number: 1024
    lock engine: pthread robust mutexes
    uwsgi socket 0 bound to UNIX address /var/run/uwsgi/myserver.sock fd 3
    Python version: 2.7.3 (default, Jan  2 2013, 14:09:21)  [GCC 4.7.2]
    Set PythonHome to /root/Envs/rootenv
    ImportError: No module named site
    
4

0 回答 0