【发布时间】:2013-07-19 10:22:31
【问题描述】:
上下文:
- WampServer 2.2 64 位(编辑:我相信我实际上有 32 位版本)
- Apache 2.2.22
- mod_wsgi 3.4 64 位:courtesy of this site
- Python 3.3.2 64 位
- django 1.5.1
python -c "import django; print(django.get_version())" 测试完美运行,所以我知道 django 安装正确。
我在 httpd.conf 中添加了 LoadModule 行来加载 mod_wsgi.so 文件,服务器重新启动没有问题。
更新:在开发服务器上运行启动项目。
我正在尝试通过tutorial #1 启动并运行启动项目演示。按照教程的建议,我将代码放在文档根目录之外的一个名为 www-src 的文件夹中(有更好的名称吗?)。我的 wampserver 的 DocumentRoot 是 DocumentRoot "c:/wamp/www/"。
文件结构如下:
|- C:
|- wamp
|- www (DocumentRoot)
|- www-src
|- first_django_site
|- first_django_site
| |- __pycache__
| | |- __init__.cpython-33.pyc
| | |- settings.cpython-33.pyc
| | |- urls.cpython-33.pyc
| | |- wsgi.cpython-33.pyc
| |- __init__.py
| |- settings.py
| |- urls.py
| |- wsgi.py
|- first_django_site.conf
|- manage.py
我希望 url 为 localhost/first-django-site,以便将其与 wamp 中的普通 php www 项目区分开来。
编写路径以访问文档根目录之外的内容的方法是什么?我不确定“../”是否有效。
这是我尝试编写适当的 apache httpd.conf 的多种方法。最好的方法和正确的方法是什么?
区块 1:
WSGIScriptAlias /first-django-site "../www-src/first_django_site/first_django_site/wsgi.py"
WSGIPythonPath "../www-src/first_django_site"
<Directory "../www-src/first_django_site/first_django_site">
Order deny,allow
Require all granted
</Directory>
第 2 块:
Alias /www-src-alias/ "c:/wamp/www-src/"
<Directory "c:/wamp/www-src/">
Order deny,allow
Require all granted
</Directory>
# alias is way above in the <Ifmodule> so redacted
WSGIScriptAlias /first-django-site "/www-src-alias/first_django_site/first_django_site/wsgi.py"
WSGIPythonPath "/www-src-alias/first_django_site"
<Directory "/www-src-alias/first_django_site/first_django_site">
Order deny,allow
Require all granted
</Directory>
第 3 块:
Include "../www-src/first_django_site/first_django_site.conf"
first_django_site.conf
<VirtualHost *:80>
ServerName localhost
#ServerAlias www.mysite.com
WSGIScriptAlias /first-django-site "../www-src/first_django_site/first_django_site/wsgi.py"
WSGIPythonPath "../www-src/first_django_site"
<Directory "../www-src/first_django_site/first_django_site">
Order deny,allow
Require all granted
</Directory>
</VirtualHost>
第 4 块:这会产生 500 内部服务器错误。
WSGIScriptAlias /first-django-site "C:/wamp/www-src/first_django_site/first_django_site/wsgi.py"
WSGIPythonPath "C:/wamp/www-src/first_django_site"
<Directory "C:/wamp/www-src/first_django_site/first_django_site">
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
【问题讨论】:
-
为什么不使用开发服务器?
-
@dan-klasson 我想练习一下在 Apache 上设置它。
-
我将从使用绝对路径而不是相对路径开始。
-
@dan-klasson 参见第 4 块(刚刚添加)。给出 500 内部服务器错误。
-
检查您的 Apache 错误日志,然后查看错误是什么。
标签: django apache wamp httpd.conf