我正在部署django项目,并收到该500错误(请参阅服务器日志错误)。
我在哪里做错了?
一些注意事项:
服务器日志错误
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] SyntaxError: invalid syntax
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] mod_wsgi (pid=6570): Target WSGI script '/new_esmart/esmart2/esmart2/wsgi.py' cannot be loaded as Python module., referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] mod_wsgi (pid=6570): Exception occurred processing WSGI script '/new_esmart/esmart2/esmart2/wsgi.py'., referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] Traceback (most recent call last):, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] File "/new_esmart/esmart2/esmart2/wsgi.py", line 13, in <module>, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] import django.core.handlers.wsgi, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] File "/new_esmart/esmart_env/lib/python2.7/site-packages/django/__init__.py", line 1, in <module>, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] from django.utils.version import get_version, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] File "/new_esmart/esmart_env/lib/python2.7/site-packages/django/utils/version.py", line 7, in <module>, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] from django.utils.lru_cache import lru_cache, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] File "/new_esmart/esmart_env/lib/python2.7/site-packages/django/utils/lru_cache.py", line 28, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] fasttypes = {int, str, frozenset, type(None)},, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] ^, referer: http://192.168.30.17/logistics/alarms/
[Wed Sep 21 17:07:54 2016] [error] [client 192.168.30.93] SyntaxError: invalid syntax, referer: http://192.168.30.17/logistics/alarms/
wsgi.py
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/new_esmart/esmart_env/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/new_esmart/esmart2')
sys.path.append('/new_esmart/esmart2/esmart2')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "esmart2.settings")
# Activate your virtual env
activate_env = os.path.expanduser("/new_esmart/esmart_env/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
application = django.core.handlers.wsgi.WSGIHandler()
httpd.conf
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /new_esmart/esmart2
ServerName logistica.org
ServerAlias www.logistica.org
WSGIScriptAlias / /new_esmart/esmart2/esmart2/wsgi.py
ErrorLog logs/logistica.org-error_log
CustomLog logs/logistica.org-access_log common
</VirtualHost>
WSGIPythonPath /new_esmart/esmart2:/new_esmart/esmart_env/lib/python2.7/site-packages
/etc/httpd/conf.d/wsgi.conf
LoadModule wsgi_module modules/mod_wsgi.so
正如Daniel指出的那样,该错误表明您的mod_wsgi是针对Python 2.6编译的。为了使用Python 2.7,您需要安装针对Python 2.7的mod_wsgi。您不能通过简单地引用Python 2.7虚拟环境来试图强迫它使用Python 2.7,但这不是它的工作原理。
您可以使用以下测试应用程序来验证使用哪个Python版本mod_wsgi进行了编译:
您将需要卸载mod_wsgi模块并安装为Python 2.7构建的模块版本,或者从系统软件包中安装(如果有),或者从源代码构建(如果没有适用于Python 2.7的mod_wsgi系统软件包)。
我还建议您检查有关使用mod_wsgi的Django文档,并确保使用其解释的守护程序模式。
请注意,Django文档仍未遵循所有最佳做法。而不是在中site-packages
显式添加python-path
,您应该使用它python-home
来引用虚拟环境。看:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句