Utiliser virtualenv appartenant à root dans un projet web python en production

J’ai donc la configuration suivante:

  • Serveur Nginx avec uWsgi
  • Projet Django dans une virtualenv

Mon virtualenv appartient à un utilisateur du système ordinal et toute la configuration fonctionne bien! Le processus uwsgi est configuré pour s’exécuter avec nginx uid & gid, ainsi que le propriétaire du processus nginx dans le fichier nginx.conf.

Mais, si j’essaie d’utiliser un autre virtualenv satisfaisant les mêmes exigences, mais appartenant à root, mon uwsgi ne peut pas localiser la virtualenv, générant une erreur d’importation.

Est-ce normal et est-ce que mon approche est correcte pour utiliser un virtualenv appartenant à la racine?

Modifier:

  • uwsgi config:

    [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 log traceback:

     *** Starting uWSGI 1.9.15 (64bit) on [Fri Sep 6 14:02:41 2013] *** comstackd 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] *** comstackd 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