在Apache中使用带有ProxyPass的mod_wsgi-express提供静态文件无效

时间:2017-01-18 17:20:22

标签: python django apache mod-wsgi

我今天发现mod_wsgi-express,我认为这是非常酷的项目。 我无法相信部署Python / Django Web应用程序只需要这个命令。

mod_wsgi-express start-server project/wsgi.py

然而,文档似乎仍然缺失(或者我没有找到?)。据我所知,官方文档中没有提及here

我在同一台机器上托管几个小网站,因此使用VirtualHost。所以我需要将它代理到另一个这样的端口:

<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName example.com
    ProxyPass "/" "http://localhost:8000"
</VirtualHost>

到目前为止一切顺利。我正在运行mod_wsgi-express,如下所示:

mod_wsgi-express start-server --url-alias /static /path/to/static project/wsgi.py 

你看,我试图在mod_wsgi-express本身设置静态文件配置。但是,不提供静态文件,并提供502代理错误。

因此代理动态请求正在运行,但不是静态文件。当在端口8000直接访问时,站点也是工作文件。我在这里缺少什么?

当然我可以在VirtualHost中添加配置来提​​供这些静态文件,但如果它与mod_wsgi-express一起使用,它将使配置更简单,更容易部署。

1 个答案:

答案 0 :(得分:0)

感谢Graham Dumpleton的评论。尽管官方文档中没有,但他已撰写有关此问题的详细博文:Redirection problems when proxying to Apache running in Docker..

虽然我没有使用Docker,但是当从Apache VirtualHost将请求代理到80或443以外的其他端口时,此解决方案是通用的。

在上面的例子中,我在VirtualHost配置中缺少两个标头。所以这是新的VirtualHost配置:

<VirtualHost *:80>
    ServerName example.com
    ProxyPass / http://localhost:8000/
    ProxyPassReverse / http://localhost:8000/
    RequestHeader set X-Forwarded-Port 80
</VirtualHost>

这就是所需要的。格雷厄姆在他的博客文章中提供了很多细节,所以如果你遇到类似的问题,还是值得一读。

相关问题