0

我已经安装了 apache 和 mod_wsgi,所有的网页都被检索和显示了,但是当我尝试访问一个静态文件(例如:http://localhost/static/css/base. css)它说我无权访问该文件,媒体文件也是如此。所以基本上返回的网页只是纯 HTML。

我已按照演示幻灯片http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-pycon-sydney-2010.pdf中的步骤操作,并通过chmod o+rx /home/loai/workspace/Faculty 我的 httpd 让其他人可以访问这些目录。 conf部分是:

WSGIScriptAlias / /home/loai/workspace/Faculty/Faculty/wsgi.py
WSGIPythonPath /home/loai/workspace/Faculty

Alias /media/ /home/loai/workspace/Faculty/Faculty/media
Alias /static/ /home/loai/workspace/Faculty/Faculty/static

<Directory /home/loai/workspace/Faculty/Faculty/static>
Order deny,allow
Allow from all
</Directory>

<Directory /home/loai/workspace/Faculty/Faculty/media>
Order deny,allow
Allow from all
</Directory>

<Directory /home/loai/workspace/Faculty/Faculty>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

奇怪的是,当我删除“文件”指令时,它变成:

<Directory /home/loai/workspace/Faculty/Faculty>
Order deny,allow
Allow from all
</Directory>

instead of 

<Directory /home/loai/workspace/Faculty/Faculty>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

然后尝试访问任何静态或媒体文件引发(未找到)而不是权限被拒绝!但仍然加载了纯 html 页面!

4

2 回答 2

2

代替:

Alias /media/ /home/loai/workspace/Faculty/Faculty/media
Alias /static/ /home/loai/workspace/Faculty/Faculty/static

采用:

Alias /media/ /home/loai/workspace/Faculty/Faculty/media/
Alias /static/ /home/loai/workspace/Faculty/Faculty/static/

如果挂载点上有斜杠,则目录上需要有斜杠。如果您没有匹配它们,则可能无法正常工作。

于 2012-12-01T07:08:20.843 回答
0

试试这个..如果它确实尝试添加媒体目录的配置。确保递归设置静态文件夹的读取权限

 <VirtualHost *:80>

    DocumentRoot /home/loai/workspace/Faculty/

    Alias /static/ /home/loai/workspace/Faculty/static/

    <Directory /home/loai/workspace/Faculty>
    Order allow,deny
    Allow from all
    </Directory> 
    <Location "/static/">
        SetHandler None
    </Location>

    WSGIScriptAlias / /home/loai/workspace/Faculty/Faculty/wsgi.py
    </VirtualHost>

更新:

我建议将您的静态文件夹复制到教师应用程序之外。我已经更改了配置文件中的路径。

于 2012-12-01T06:44:53.220 回答