【发布时间】:2016-10-10 02:23:19
【问题描述】:
我有点卡住了。我不能让这个配置工作,我不知道为什么。我在下面的代码来自https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04。我坚持下去的原因是因为他将他的项目目录和他的项目命名为相同的东西。如果我是对的,那么他在哪里定位诸如 settings.py 和 wsgi.py 之类的文件应该是 /home/user/myproject/myproject/myproject 但我不确定了,因为我自己什至无法正确处理。在文档的前面,他 cd 进入了他创建的目录,这会将他放在 /home/user/myproject 中。然后他继续创建一个虚拟环境,输入它并运行django-admin startproject myproject。所以,如果这一切都成立,至少我在我自己的服务器上看到的告诉我,当你启动一个 django 项目时,它实际上会创建两个同名的文件夹,嵌套。我错了吗?有人可以帮我理顺下面的代码以使其更有意义吗?
. . .
Alias /static /home/user/myproject/static
<Directory /home/user/myproject/static>
Require all granted
</Directory>
<Directory /home/user/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-path=/home/user/myproject:/home/user/myproject/myprojectenv/lib/python2.7/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/user/myproject/myproject/wsgi.py
</VirtualHost>
这是我在 apache 日志中一直看到的内容:
[Sun Oct 09 11:48:15.875313 2016] [wsgi:warn] [pid 47964] mod_wsgi: Compiled for Python/3.5.1+.
[Sun Oct 09 11:48:15.875353 2016] [wsgi:warn] [pid 47964] mod_wsgi: Runtime using Python/3.5.2.
[Sun Oct 09 11:48:15.877537 2016] [mpm_prefork:notice] [pid 47964] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Sun Oct 09 11:48:15.877568 2016] [core:notice] [pid 47964] AH00094: Command line: '/usr/sbin/apache2'
[Sun Oct 09 11:48:18.767800 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] mod_wsgi (pid=47967): Target WSGI script '/home/addohm/projects/rtservice/servicesite/servicesite/wsgi.py' cannot be loaded as Python module.
[Sun Oct 09 11:48:18.767851 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] mod_wsgi (pid=47967): Exception occurred processing WSGI script '/home/addohm/projects/rtservice/servicesite/servicesite/wsgi.py'.
[Sun Oct 09 11:48:18.768339 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] Traceback (most recent call last):
[Sun Oct 09 11:48:18.768385 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/home/addohm/projects/rtservice/servicesite/servicesite/wsgi.py", line 16, in <module>
[Sun Oct 09 11:48:18.768389 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] application = get_wsgi_application()
[Sun Oct 09 11:48:18.768395 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Sun Oct 09 11:48:18.768398 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] django.setup()
[Sun Oct 09 11:48:18.768405 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3/dist-packages/django/__init__.py", line 17, in setup
[Sun Oct 09 11:48:18.768408 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Sun Oct 09 11:48:18.768413 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 48, in __getattr__
[Sun Oct 09 11:48:18.768423 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] self._setup(name)
[Sun Oct 09 11:48:18.768430 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 44, in _setup
[Sun Oct 09 11:48:18.768433 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] self._wrapped = Settings(settings_module)
[Sun Oct 09 11:48:18.768438 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3/dist-packages/django/conf/__init__.py", line 92, in __init__
[Sun Oct 09 11:48:18.768441 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] mod = importlib.import_module(self.SETTINGS_MODULE)
[Sun Oct 09 11:48:18.768446 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Sun Oct 09 11:48:18.768449 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] return _bootstrap._gcd_import(name[level:], package, level)
[Sun Oct 09 11:48:18.768454 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Sun Oct 09 11:48:18.768460 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Sun Oct 09 11:48:18.768466 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Sun Oct 09 11:48:18.768471 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Sun Oct 09 11:48:18.768477 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Sun Oct 09 11:48:18.768483 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Sun Oct 09 11:48:18.768488 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Sun Oct 09 11:48:18.768505 2016] [wsgi:error] [pid 47967] [remote 192.168.2.249:22662] ImportError: No module named 'servicesite'
【问题讨论】:
-
我不确定你的问题是什么。您只需要使 Apache 配置中的目录与您的目录布局相匹配,无论它是什么。
-
您是否阅读过有关如何设置 mod_wsgi 的官方 Django 文档? docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi
-
@Graham 这是同样的斗争。假设我在
~/projects/projectfolder。然后我run django-admin startproject mysite。 django generated 文件夹变为~/projects/projectfolder/mysite,settings.py 和wsgi.py 的位置变为~/projects/projectfolder/mysite/mysite所以在查看站点文档时,我不得不假设mysite.com 只是项目文件夹他们创建并进入该目录,然后创建了 mysite 项目。 -
@Graham-Dumpleton 采用上述方法(请记住,我在这篇文章中使用 ~ 来保持路径短......马上
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py变得错误。使用我的例子,@ 987654331@ 是文件的正确路径,而不是~/projects/projectfolder/mysite/wsgi.py。假设mysite.com是他们创建的django-admin 项目,那么为什么二级文件夹是mysite而不是mysite.com?当我创建项目时,它会在项目文件夹中创建./projectname/projectname和./manage.py。 -
@GrahamDumpleton 有趣的是,
mysite.com不是一个有效的项目名称,这只会进一步证明我的观点。
标签: python django apache mod-wsgi