1

我有一个通常在 https 中工作的应用程序。Tomcat 监听 8443 端口:

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
           maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
           clientAuth="false" sslProtocol="TLS"
           keyAlias="MY_ALLIAS" keystoreFile="PATH_TO_MY_KEY"
           keystorePass="MY_PASWORD" />

Apache 监听 80 并重定向到 8443:

<VirtualHost *:80>
        ServerAdmin MY_EMAIL_ADDRESS
        ServerName localhost
        ServerAlias localhost
        ProxyPass / http://localhost:8443/
        ProxyPassReverse / http://localhost:8443/
        DocumentRoot /var/www/html

最后在 web.xml 中我添加了:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>MY_WEB_RESOURCE_NAME</web-resource-name>
        <url-pattern>/welcome</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

不幸的是,我必须将带有 http 站点的 IFRAME 添加到我的一个网站中。那里的安全不是问题。我的问题是Tomcat配置。我想我会用 Apache 调度流量。但是现在我的问题是如何设置 Tomcat,这样我就可以为站点http://localhost:8080/siteA提供服务,而所有其他站点都将在https://localhost:8443/myOtherSites 上提供服务?我尝试删除 redirectPort="8443",但这还不够。我正在使用 Tomcat 9.0.0.M4(如果需要,迁移到 Tomcat 8 不是问题)。请帮忙!

4

1 回答 1

1

要解决此问题<security-constraint>,请在您的 web.xml 中再添加一个标签,如下所示 `

<security-constraint>
<web-resource-collection>
<web-resource-name>Unsecured resources</web-resource-name>
<url-pattern>/siteA</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint> `

由于您已将 transport-guarantee 设置为 NONE ,tomcat 将不会验证它是否是受保护的资源。通过这种方式,这<security-constraint>将有助于访问您的siteAover http 并且<security-constraint>您已经声明的其他标签将帮助您访问您的其他网站https。请记住,在<url-pattern>标签中给出要保留为 http 或 https 的页面的路径,让我知道这是否解决了您的问题 :)。

于 2016-06-25T11:11:55.173 回答