我需要将路径映射到我的tomcat Web应用程序。我为此使用了proxypass。这是apache2中的当前配置
<VirtualHost *:80> ServerName localhost:80 ProxyPass /app http://localhost:8088/ui/ ProxyPassReverse /app http://localhost:8088/ui/ ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
这是从tomcat获取HTML,但是形成的css url错误。而不是http://localhost/app/css/style.cssurl被映射为http://localhost/ui/css/style.css。
http://localhost/app/css/style.css
http://localhost/ui/css/style.css
我尝试使用重写,但是没有用。
RewriteEngine on RewriteRule ^/ui/ /app/
我需要找到正确的方法来更正URL。任何帮助将不胜感激!提前致谢。
经过大量的反复试验,我找到了解决问题的两种不同方法。
<VirtualHost *:80> ProxyPreserveHost On ProxyPass /app http://localhost:8080/ui/ ProxyPassReverse /app http://localhost:8080/ui/ #since in java web app the context started with /ui the js src had /ui in the beginning #this resulted in 404 so I had to rewrite all request to /ui to forward to /app RewriteEngine on RewriteRule "^/ui(.+)" "/app$1" [R,L] ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
ln -s ui app
现在,apache配置为:
<VirtualHost *:80> ProxyPreserveHost On <Location /app> ProxyPass ajp://localhost:8019/app/ ProxyPassReverse ajp://localhost:8019/app/ SetOutputFilter proxy-html ProxyHTMLExtended On ProxyHTMLURLMap /app /app RequestHeader unset Accept-Encoding </Location> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
在第一种解决方案中,重写mod导致请求在重定向到正确的url之前返回304。这就是默认情况下的工作方式。
在第二种解决方案中,由于两个处理程序都是相同的(/ app),因此无需重新定向,并且URL正确映射。