在apache后面的gunicorn链接到本地​​主机

我有一个使用mod_proxy在Apache后面的gunicorn服务器。

Gunicorn在http://localhost:8080/ 。 假设我的服务器位于http://example.com/

有时,当我发布一个无效的链接到我的服务器(如忘记尾随),让我们说http://example.com/with-no-trailing-slash ,用户被redirect到http://localhost:8080/with-no-trailing-slash ,因为客户机上没有服务器,所以无效。

你知道为什么它的行为? 如何解决这个问题?

要启动gunicorn我这样做: sudo gunicorn -b localhost:8080 app:app

 <VirtualHost *:80> ServerName example.com ServerAlias example.com DocumentRoot /opt/example <Proxy *> AuthType basic AuthBasicAuthoritative Off SetEnv proxy-chain-auth On Order allow,deny Allow from all </Proxy> # Let apache serve static files ProxyPass /robots.txt ! ProxyPass /favicon.ico ! ProxyPass /static/ ! Alias /static/ /opt/example/app/static/ # Gunicorn handle the others ProxyPass / http://localhost:8080/ # robots.txt et favicon.ico sont dans /path/to/django/project/static/ Alias /robots.txt /path/to/django/project/static/robots.txt Alias /favicon.ico /path/to/django/project/static/favicon.ico Alias /favicon.ico /path/to/django/project/static/favicon.ico <Directory /path/to/django/project> Order deny,allow Allow from all Options -Indexes </Directory> </VirtualHost> 

如果你需要另一个configuration文件,让我知道!

您错过了反向映射,这对ApacheredirectURL重写而言非常有用。 在99%的情况下,正向和反向映射是相同的。

添加这个:

 ProxyPassReverse / http://localhost:8080/ 

并重新加载Apache。