【发布时间】:2017-09-12 09:57:09
【问题描述】:
我在 Apache 中设置 WSGIScriptAlias 时遇到了问题,尝试使用别名会由于尝试访问“文字”URL 而导致 404 错误。这是我的 Apache2 sites-available/000-default.conf 中的测试设置(模仿 mod_wsgi Quick Start Guide):
DocumentRoot /var/www/html
WSGIScriptAlias /wsgi_test /var/www/html/test.wsgi
<Directory /var/www/html>
Order allow,deny
Allow from all
</Directory>
重启Apache2并进入mydomain.com/wsgi_test后,显示404页面。下面 Apache 的 error.log 文件的第一行显示了服务器试图访问 DocumentRoot 中的 URL 路径 wsgi_test,而不是别名文件路径:
AH00128: File does not exist: /var/www/html/wsgi_test
AH01964: Connection to child 1 established (server nathanclonts.com:443)
(70007)The timeout specified has expired: [client 67.161.148.188:33883] AH01991: SSL input filter read failed.
文件/var/www/html/test.wsgi的代码与上述快速入门指南相同:
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
权限设置为:
-rwxrw-r-- 1 username www-data 278 Apr 16 11:31 test.wsgi
有没有人建议在哪里寻找可能会影响这一点的其他配置,或任何其他调试技巧?
奇怪的是,我已经使用 mod_wsgi 设置了另一个(Django)应用程序,该应用程序当前在同一个 VirtualHost 中工作,但显然我在这个测试中遗漏了一些东西。
【问题讨论】:
-
相对于您添加的内容,Django 配置在哪里定义?如果django应用在'/'的路径下,那么这里添加的内容必须在那个之前,否则django应用的'/'匹配优先。
-
原来这只是一般别名配置的问题:[WSGIScript]别名是为
VirtualHost *定义的,但不是为VirtualHost *:433定义的(服务器使用SSL)。将它们添加到 `VirtualHost *:433 文件修复了它。不过感谢您的建议,请记住这一点!
标签: apache ubuntu apache2 mod-wsgi wsgi