1

所以我见过的每个 web.py 教程都包含这一行:

urls = (
    '/', 'index',
)

然后,稍后,使用 GET 函数等定义索引类。我的问题是,这不起作用。使用上面的代码,我得到一个 404 错误。使用以下映射工作:

urls = (
    '/.*', 'index',
)

但这至少在一开始会捕获每一个可能的 URL,我只希望“索引”处理对域根目录的访问。哈普?

一些基本信息:

Python 2.6、web.py 0.3、带有 mod_wsgi 的 Apache 2.2

不知道还有什么有用的,所以如果我可以添加一些重要的东西(也许是来自 Apache 的 VirtualHost?)请询问,我会在这里添加它。

编辑:包括我的 Apache VirtualHost 配置:

<VirtualHost *:80>
    ServerName dd.sp4.us
    DocumentRoot /home/steve/www/nov2010/public/
    ErrorLog /home/steve/www/nov2010/log/error.log
    CustomLog /home/steve/www/nov2010/log/access.log combined

    WSGIScriptAlias / /home/steve/www/nov2010/app
    Alias /static /home/steve/www/nov2010/public

    <Directory /home/steve/www/nov2010/app>
        SetHandler wsgi-script
        Options ExecCGI
    </Directory>

    AddType text/html .py

    <Location />
        RewriteEngine on
        RewriteBase /
        RewriteCond %{REQUEST_URI} !^/static
        RewriteCond %{REQUEST_URI} !^(/.*)+code.py/
        RewriteRule ^(.*)$ code.py/$1 [PT]
    </Location>
</VirtualHost>
4

1 回答 1

5

对于背景阅读:

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

假设您只有一个 WSGI 应用程序要挂载在站点的根目录,并且只有静态文件或其他资源在 /static 下,那么而不是:

WSGIScriptAlias / /home/steve/www/nov2010/app
Alias /static /home/steve/www/nov2010/public

<Directory /home/steve/www/nov2010/app>
    SetHandler wsgi-script
    Options ExecCGI
</Directory>

AddType text/html .py

<Location />
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/static
    RewriteCond %{REQUEST_URI} !^(/.*)+code.py/
    RewriteRule ^(.*)$ code.py/$1 [PT]
</Location>

采用:

Alias /static /home/steve/www/nov2010/public

WSGIScriptAlias / /home/steve/www/nov2010/app/code.py

<Directory /home/steve/www/nov2010/app>
Order allow,deny
Allow from all
</Directory>

您正在混合配置不应该一起使用的 mod_wsgi 的多种方式。

如果您的要求是其他内容,那么您将必须更清楚地了解您想要发生的事情。

于 2010-09-03T03:43:06.730 回答