nginx + uwsgi在vhost模式下运行django应用程序的问题

我在我的服务器上有几个django应用程序,完全运行在自己的套接字文件上,但是我打算介绍一些更多的django应用程序,所以我更喜欢在vhost模式下运行uwsgi,但是它似乎有一些导入/path

这里是nginx的虚拟主机configuration

location / { include uwsgi_params; uwsgi_param UWSGI_PYHOME /home/httpd/django.udm.local/public_html; uwsgi_param UWSGI_PYHOME /home/httpd/django.udm.local/public_html; uwsgi_param UWSGI_PYTHONPATH /home/httpd/django.udm.local/public_html; uwsgi_param UWSGI_CHDIR /home/httpd/django.udm.local/public_html uwsgi_param UWSGI_ENV DJANGO_SETTINGS_MODULE=settings; uwsgi_param UWSGI_MODULE mysite; uwsgi_pass 127.0.0.1:1088; 

并在“mysite.py”文件中我有这样的:

 import os, sys sys.path.append(os.path.dirname(__file__)) os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 

我用这个命令运行uwsgi:

 uwsgi -s 127.0.0.1:1088 -M --no-site --vhost 

这是错误

 *** Operational MODE: single process *** *** no app loaded. going in full dynamic mode *** *** uWSGI is running in multiple interpreter mode *** spawned uWSGI master process (pid: 1838) spawned uWSGI worker 1 (pid: 1839, cores: 1) Traceback (most recent call last): File "./mysite.py", line 7, in <module> import django.core.handlers.wsgi ImportError: No module named django.core.handlers.wsgi unable to load app SCRIPT_NAME=django.udm.local| 

正如你可以想象的,django已经正确的安装在系统上

 # python Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import django.core.handlers.wsgi >>> 

谢谢!

更新 18/8终于我find了解决scheme..我已经改变了mysite.py文件,并添加到Django和Python库的path

 import os, sys sys.path.append(os.path.dirname(__file__)) sys.path.append('/usr/lib/pymodules/python2.6') sys.path.append('/usr/lib/python2.6/dist-packages') os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() 

UWSGI_PYHOME将设置一个virtualenv,所以如果你不在virtualenv你必须删除它。 你可能对这个配置感兴趣: http : //projects.unbit.it/uwsgi/wiki/TipsAndTricks

我不认为这是正确的在wsgi文件中添加的东西。 这实际上是硬编码的。

如果您将代码部署到不同的系统甚至不同版本的Python,会发生什么? 也许python2.6,python2.7 .etc,所以必须在部署的服务器上追加正确的sys.path。