简体   繁体   English

Django WSGI Apache VirtualHost,返回404错误

[英]Django WSGI Apache VirtualHost, returning a 404 Error

  • Ubuntu 12.04 Ubuntu 12.04
  • Apache 2.2.2 Apache 2.2.2
  • Python 3.2.3 Python 3.2.3
  • Django 1.6.1 Django 1.6.1

I followed directions at Using mod_wsgi to Serve Applications on Ubuntu 12.04 , for setting up a WSGI for my Django on Apache. 我按照使用mod_wsgi在Ubuntu 12.04上应用程序提供服务的指示,为Apache上的Django设置WSGI。 Problem is, the VirtualHost domain is now returning a confusingly weird 404 error: 问题是,VirtualHost域现在返回一个令人困惑的奇怪的404错误:

[Mon Dec 16 19:53:49 2013] [error] [client 127.0.0.1] File does not exist: /etc/apache2/htdocs

It's confusing because... that directory doesn't even exist . 这令人困惑,因为...该目录甚至不存在 The VirtualHost is setup in /var/www/main and the config's for it in /var/apache2/sites-available/default looks like this: VirtualHost在/ var / www / main中设置,其中/ var / apache2 / sites-available / default中的配置如下所示:

<VirtualHost *:80>
        ServerName 127.0.0.1
        ServerAlias coral
        WSGIScriptAlias / /home/dfy/code/djdev/djdev/wsgi.py
</VirtualHost>

I reloaded Apache after editing. 我在编辑后重新加载了Apache。 That wsgi file is the one generated by Django when I started the project. 当我启动项目时,那个wsgi文件是Django生成的文件。 I altered it to match what was needed according to the tutorial: 我根据教程修改了它以匹配所需的内容:

import os
import sys # added from tutorial
sys.path.append('/home/dfy/code/djdev/djdev/') # added from tutorial
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djdev.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

To me, this all looks like it should work, but Apache is lookin' for static files in a non-existent directory (/etc/apache2/htdocs). 对我来说,这一切看起来应该可行,但Apache正在查找不存在的目录中的静态文件(/ etc / apache2 / htdocs)。 I've been Googling for hours trying to figure out what's wrong here, but haven't found the answer. 我一直在谷歌搜索几个小时试图弄清楚这里有什么问题,但还没有找到答案。 On a whim I tried chmod 777 wsgi.py , but that didn't change anything, so I'm sure it's not a permissions problem. 一时兴起,我尝试了chmod 777 wsgi.py ,但这没有改变任何东西,所以我确定这不是权限问题。 I really no idea what's gone wrong. 我真的不知道出了什么问题。

but Apache is lookin' for static files in a non-existent directory 但Apache正在查找不存在的目录中的静态文件

I'm not sure what is going on here, but I suspect your main configuration is not correct. 我不确定这里发生了什么,但我怀疑你的主要配置是不正确的。 If you do not supply a DOCUMENT_ROOT , Apache will look for it in the default location, which is htdocs . 如果您不提供DOCUMENT_ROOT ,Apache将在默认位置(即htdocs查找它。

As per the django documentation on deployment , you need to provide the following configuration for your virutal host. 根据有关部署django文档 ,您需要为虚拟主机提供以下配置。 You chould change the paths as they apply to your setup: 您可以更改适用于您的设置的路径:

Alias /robots.txt /path/to/mysite.com/static/robots.txt

Alias /favicon.ico /path/to/mysite.com/static/favicon.ico

AliasMatch ^/([^/]*\.css) /path/to/mysite.com/static/styles/$1

Alias /media/ /path/to/mysite.com/media/
Alias /static/ /path/to/mysite.com/static/

<Directory /path/to/mysite.com/static>
    Order deny,allow
    Allow from all
</Directory>

<Directory /path/to/mysite.com/media>
    Order deny,allow
    Allow from all
</Directory>

WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com

<Directory /path/to/mysite.com/mysite>
    <Files wsgi.py>
        Order deny,allow
        Require all granted
    </Files>
</Directory>

Please use the official docs which are updated with changes to specific django versions. 请使用随特定django版本更改而更新的官方文档。

Maybe your loosing something: In my vhost configuration I have: 也许你失去了一些东西:在我的vhost配置中,我有:

<virtualhost *:80>
...
Alias /static/ /the/path/to/static/
<Location "/static/">
        Options -Indexes
</Location>
...

</virtualhost>

I hope it helps 我希望它有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM