【问题标题】:Serving html files in /var/www alongwith Django over Apache通过 Apache 在 /var/www 和 Django 中提供 html 文件
【发布时间】:2012-01-26 15:08:29
【问题描述】:

我的 Apache Mod_WSGI 和 Django 在 http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/ 之后工作,但我的 000-default 站点包含内容

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/nipun/webdev/demo/demo

    <Directory /home/nipun/webdev/demo/demo>
    Order allow,deny
    Allow from all


    WSGIDaemonProcess demo.djangoserver processes=2 threads=15 display-name=%{GROUP}
    WSGIProcessGroup demo.djangoserver

    WSGIScriptAlias / /home/nipun/webdev/demo/demo/apache/django.wsgi
    </Directory>



DocumentRoot /var/www
<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>


所以使用这个配置,我基本上可以为我的 Django 网站提供服务,比如 http://localhost/meta 例如 meta 调用相应视图的地方

但是现在当我尝试加载位于我的 /var/www 上的 index.html(其中包含一些 javascript 和 html 代码)时,它会尝试使用 URL 来匹配它 在我用 Apache 配置的 Django 项目的 urls.py 中指定。

如何修改设置,以便能够在 /var/www 下提供脚本以及在 localhost 上提供 Django 站点

尝试第一个答案中给出的方法后 所以我添加了这一行

Alias / /var/www

在包含

的行之上
WSGIDaemon...

现在 django 站点和我在 /var/www 中的文件都不起作用

已解决 将 000-default 文件更改为:

<VirtualHost *:80>  
ServerAdmin webmaster@localhost
DocumentRoot /var/www
Alias /robots.txt /var/www/robots.txt
Alias /testing.php /var/www/testing.php
Alias /index.html  /var/www/index.html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
DocumentRoot /home/nipun/webdev/demo/demo
WSGIDaemonProcess demo.djangoserver processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup demo.djangoserver
WSGIScriptAlias / /home/nipun/webdev/demo/demo/apache/django.wsgi
<Directory /home/nipun/webdev/demo/demo>
   Order allow,deny
   Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined




</VirtualHost>


为了让它更智能,别名匹配可以像这样完成

AliasMatch /([^/]+).html /home/nipun/webdev/application_layer/$1.html

【问题讨论】:

    标签: python django apache mod-wsgi


    【解决方案1】:

    阅读章节中的文档:

    http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive

    使用该部分末尾解释的 AddHandler/mod_rewrite/WSGI 脚本修复方法。

    使用该方法,如果存在静态文件,那么它将被提供,否则 Django 实例充当所有其他 URL 的后备资源。

    【讨论】:

      【解决方案2】:

      首先,我不知道您为什么一直在谈论“运行”您的 HTML 文件。它不是一个脚本,即使它里面有 Javascript - 那只是为了客户端。没有什么可以运行,Apache 只需要提供文件。

      其次,您显然需要某种方法来区分发送给 Django 的请求和直接获得服务的请求。最简单的方法是将一个或另一个放在子目录中 - 要么将 WSGIScriptAlias 路径从 \ 更改为 my_django_site,要么使用普通的 Alias 来设置静态文件的位置。如果你做后者,你需要将指令放在 WSGI 部分之上,以便它首先匹配。

      【讨论】:

      • 嗨。感谢您的回复。我尝试了您的方法,但仍然无法正常工作。我已添加有关该问题的详细信息
      • 除非你没有按照我说的去做:我说你需要将其中一个放到子目录中,而你没有这样做。
      • 我实际上已经做到了(将 wsgialias 修改为 /a)并且它也对我有用。但我想使用 / 作为 wsgialias 。所以这就是为什么我尝试了我无法使用的第二种方法让它工作。实际上我要解决的问题需要我从 / 运行这两个东西
      • 但是您是否看不出您需要一些方法来区分您希望 Apache 服务的请求和您希望路由到 Django 的请求?
      • 我知道需要能够区分请求,但我要解决的问题需要我运行 localhost/meta 和 localhost/index.html,其中第一个是 Django url 和第二个是位于 /var/www 下的普通 html
      猜你喜欢
      • 2017-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      相关资源
      最近更新 更多