我在Ubuntu 16.04上运行Apache 2.4.18。我已经设置了一个具有以下设置的虚拟服务器。虚拟主机已在a2ensite中注册,似乎正在被访问。
<VirtualHost *:80>
ServerName www.factsfromfigures.com
WSGIScriptAlias / /home/user/mycode/mysite/mysite/wsgi.py
<Directory /home/user/mycode/mysite/>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
运行时,我在Apache日志中收到以下错误。
[Thu Mar 01 17:35:00.968878 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] mod_wsgi (pid=12278): Target WSGI script '/home/user/mycode/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[Thu Mar 01 17:35:00.968895 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] mod_wsgi (pid=12278): Exception occurred processing WSGI script '/home/user/mycode/mysite/mysite/wsgi.py'.
[Thu Mar 01 17:35:00.968923 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] Traceback (most recent call last):
[Thu Mar 01 17:35:00.968933 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] File "/home/user/mycode/mysite/mysite/wsgi.py", line 18, in <module>
[Thu Mar 01 17:35:00.968964 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] application = get_wsgi_application()
[Thu Mar 01 17:35:00.968971 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] File "/usr/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Thu Mar 01 17:35:00.968988 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] django.setup()
[Thu Mar 01 17:35:00.968992 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] File "/usr/lib/python2.7/dist-packages/django/__init__.py", line 17, in setup
[Thu Mar 01 17:35:00.969007 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Mar 01 17:35:00.969024 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] File "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 48, in __getattr__
[Thu Mar 01 17:35:00.969057 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] self._setup(name)
[Thu Mar 01 17:35:00.969062 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] File "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 44, in _setup
[Thu Mar 01 17:35:00.969075 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] self._wrapped = Settings(settings_module)
[Thu Mar 01 17:35:00.969079 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] File "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 92, in __init__
[Thu Mar 01 17:35:00.969084 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Mar 01 17:35:00.969087 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu Mar 01 17:35:00.969103 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] __import__(name)
[Thu Mar 01 17:35:00.969113 2018] [wsgi:error] [pid 12278] [client 192.168.1.68:61552] ImportError: No module named mysite.settings
mysite settings.py文件位于/home/user/mycode/mysite/mysite/settings.py
wsgi.py文件位于/home/user/mycode/mysite/mysite/wsgi.py
我不确定服务器正在访问哪个版本的python,因为我在日志中收到了这些警告消息:(我不知道它为什么报告2个不同的版本)
[Thu Mar 01 18:32:03.219991 2018] [wsgi:warn] [pid 13753] mod_wsgi: Compiled for Python/2.7.11.
[Thu Mar 01 18:32:03.220008 2018] [wsgi:warn] [pid 13753] mod_wsgi: Runtime using Python/2.7.12.
我的历史就是我采用了非常好的Python和Django课程。我有40年的编程经验,因此不会发现编码问题。我对Linux / Ubuntu比较陌生,并且花了一个多星期的时间试图在我的浏览器上出现“hello world”。文件不清楚。例如,官方Django文档建议在httpd.conf中放置各种设置,但没有一个。我已经尝试了关于SO的所有建议,但似乎没有任何效果。
现在我猜这可能是一个糟糕的礼节,但我已经绝望了,并且即将放弃Django。我真的很想有人知道他们的方式来帮助我。我可以用适当数量的亚马逊优惠券或礼物奖励。我安装了RealVNC,因此您可以登录并查看,因为服务器上没有任何敏感信息。问题的真相是我是一名开发人员,并且发现系统管理/配置方面很困难。感谢您的关注,希望您能帮助我。
答案 0 :(得分:1)
<Directory /home/user/mycode/mysite/>
处的路径不完整。它应该是<Directory /home/user/mycode/mysite/mysite>
(请注意mysite
应该出现两次)。
无论如何,从一个旧项目,这是我的apache配置文件的样子:
WSGIScriptAlias / /home/user/mycode/mysite/mysite/wsgi.py
WSGIPythonPath /home/user/mycode/mysite/mysite
<Directory /home/user/mycode/mysite/mysite>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>