在 Apache2 Http 后面使用 Tomcat 并使用不同的上下文路径

在 Apache2 Http 后面使用 Tomcat 并使用不同的上下文路径

在我们的 Ubuntu Web 服务器上,我们有一个 Apache2 HTTP 服务器,以及一个在 Tomcat8 应用服务器上运行的 JSF 应用程序,使用 AJP 1.3 连接器和 HTTPS/SSL。我希望我的应用程序在 localhost:8009/myApp/ 上运行,可以从 https://subdomain.domain.com(当然,子域和域是占位符)。换句话说,我想要不同的上下文路径(apache2 上的 /,tomcat 上的 /myApp)

现在我面临的问题是 - 虽然欢迎页面可以访问 - 但所有资源/图像/链接都已损坏,因为它们仍包含上下文路径 /myApp。我尝试设置相应的 ProxPass/ReverseProxyPass 设置,但没有成功。

<VirtualHost _default_:443>
        ServerAdmin [email protected]
        DocumentRoot /srv/www/subdomain.domain.com
        ServerName subdomain.domain.com

        RewriteEngine On
        RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]
        RewriteRule .? https://subdomain.domain.com%{REQUEST_URI} [R=301,L]

        <Location />
                ProxyPass ajp://localhost:8009/myApp/ connectiontimeout=5 timeout=300
                ProxyPassReverse https://localhost:8080/myApp/
                ProxyPassReverse https://subdomain.domain.com/myApp/
                ProxyPassReverse ajp://localhost:8009/myApp/
                ProxyPassReverseCookiePath /myApp/ /

                #Order deny,allow
                Allow from all
        </Location>

</VirtualHost>

PS:作为一种解决方法,myApp 当前在 tomcat 上的根上下文“/”上运行,但我想改变它以适应多个 Web 应用程序。

在 tomcat 的 conf/server.xml 中我配置了以下连接器:

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"
           address="127.0.0.1"
           proxyName="subdomain.domain.com" proxyPort="443" secure="true" />

答案1

您可以尝试添加这个重写条件:

RewriteCond %{REQUEST_URI} ^/myApp/ [NC]
RewriteRule ^/myApp(.*) https://subdomain.domain.com$1 [R=301,L]

这样你的额外内容应该有正确的链接:

https://localhost:8080/myApp/而不是https://localhost:8080/myApp/myApp/

相关内容