Apache proxypass不解析图像和css等资源的url

Apache proxypass不解析图像和css等资源的url,apache,tomcat,mod-rewrite,mod-proxy,proxypass,Apache,Tomcat,Mod Rewrite,Mod Proxy,Proxypass,我需要映射到tomcat web应用程序的路径。我用proxypass来做这个。 这是apache2中的当前配置 <VirtualHost *:80> ServerName localhost:80 ProxyPass /app http://localhost:8088/ui/ ProxyPassReverse /app http://localhost:8088/ui/ ErrorLog ${APACHE_LOG

我需要映射到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>
我需要找到正确的方法来更正URL。
任何帮助都将不胜感激!提前感谢。

这取决于您希望显示的URL是什么。如果你想的话

然后,您需要在WAR中将静态内容移动到/ui/下

如果你愿意

然后应该从ProxyPass行中删除尾部/ui


作为第三个选项,您可以在tomcat webapp目录中创建指向“ui”的“ROOT”符号链接(并从代理中删除/ui),这将允许您从tomcat路径的根目录为您的应用提供服务。

经过大量的尝试和错误,我找到了两种不同的解决方案

  • 使用mod_rewrite和对proxypass的一些更改:

    <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>
    
    在第一种解决方案中,重写模块使请求在重定向到正确的url之前返回304。默认情况下,它就是这样工作的


    在第二种解决方案中,由于两个处理程序都是相同的(/app),因此没有理由重定向,并且URL映射正确。

    /ui是webapp的上下文路径。删除它会将/app指向tomcats base/Yes,这样当您向它发出请求时,它就会转到正确的位置。您尚未在URL中说明实际需要的内容。我希望将localhost/app映射到localhost:8088/ui。对localhost/app/ui的请求将不起作用,因为/ui已映射到/app。我可以得到/ui的html,但是css都是以/ui开头的相对url。所以我需要找到一种方法来解决这个问题。好吧,你仍然没有说你想在你的URL中看到什么。除非你这么说,否则我帮不了你。是否要查看/ui/或不查看?我可以猜一猜,然后说你应该按照我的第二个建议,在tomcat中添加一个根符号链接。我希望每个url都映射到/app,包括js和css。
    <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>
    
    <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>