Mod rewrite 代理并重写到WebApp
我正在本地使用gunicorn在Mod rewrite 代理并重写到WebApp,mod-rewrite,apache2,reverse-proxy,Mod Rewrite,Apache2,Reverse Proxy,我正在本地使用gunicorn在127.0.0.1:8000上运行一个webapp。我想在http://127.0.0.1/internal并将所有对/demo的调用重写为内部调用 我正在使用ApacheV2.4 使用mod_proxy和mod_rewrite的几种方法 # This gives me `ERR_TOO_MANY_REDIRECTS`. <Location /internal> ProxyPass http://localhost
127.0.0.1:8000
上运行一个webapp。我想在http://127.0.0.1/internal
并将所有对/demo的调用重写为内部调用
我正在使用ApacheV2.4
使用mod_proxy
和mod_rewrite
的几种方法
# This gives me `ERR_TOO_MANY_REDIRECTS`.
<Location /internal>
ProxyPass http://localhost:8000/demo
ProxyPassReverse http://localhost:8000/demo
RequestHeader add X-Script-Name "/internal"
</Location>
# This works, but I need to visit /internal/demo manually.
<Location /internal>
ProxyPass http://localhost:8000
ProxyPassReverse http://localhost:8000
RequestHeader add X-Script-Name "/internal"
</Location>
但将此添加到Apache2中无助于:
RewriteRule /internal$ /internal/demo [R,L]
看来你想要实现两件事:
/internal/
,而不是/
/demo/
子文件夹上移到应用程序的根/
(就用户的视图而言)<Location /internal>
ProxyPass http://localhost:8000/internal
ProxyPassReverse http://localhost:8000/internal
RequestHeader add X-Script-Name "/internal"
</Location>
ProxyPasshttp://localhost:8000/internal
ProxyPassReversehttp://localhost:8000/internal
RequestHeader添加X-Script-Name“/内部”
然后,为了实现(2),我将让apache proxy完成这项工作:
<Location /internal>
ProxyPass http://localhost:8000/internal/demo
ProxyPassReverse http://localhost:8000/internal/demo
RequestHeader add X-Script-Name "/internal"
</Location>
ProxyPasshttp://localhost:8000/internal/demo
ProxyPassReversehttp://localhost:8000/internal/demo
RequestHeader添加X-Script-Name“/内部”
警告:我只是偶然发现了(1)的解决方案,它确实实现了我想要实现的目标,但我还不明白为什么它会起作用
<Location /internal>
ProxyPass http://localhost:8000/internal
ProxyPassReverse http://localhost:8000/internal
RequestHeader add X-Script-Name "/internal"
</Location>
<Location /internal>
ProxyPass http://localhost:8000/internal/demo
ProxyPassReverse http://localhost:8000/internal/demo
RequestHeader add X-Script-Name "/internal"
</Location>