gpt4 book ai didi

java - tomcat 中特定页面/url 模式的 SSL

转载 作者:搜寻专家 更新时间:2023-10-31 19:41:57 24 4
gpt4 key购买 nike

我最近为 tomcat 6 配置了 SSL 和客户端身份验证,但我唯一能做的就是修改服务器配置文件(web.xml、server.xml)。但是由于我不能完全控制部署服务器,所以我想只为我的应用程序的某些页面或 url-patterns 配置所有内容,而不修改主要配置文件。

例如:主服务器:

  • 应用程序 1 -> HTTP
  • 应用程序 2 -> HTTP
  • 我的应用程序 -> HTTPS

如果有人知道怎么做,请告诉我。

最佳答案

让 https 运行的唯一方法是在 server.xml 上编写适当的连接器<service> 下的文件标签。设置连接器后,您可以使用 http 或 https 访问服务器中的所有应用程序。唯一的区别是使用什么连接器。通常,http 和 https 的连接器如下所示:

<Connector port="80" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
redirectPort="443"
URIEncoding="UTF-8" compression="on"/>

<Connector port="443" protocol="HTTP/1.1"
maxThreads="150" connectionTimeout="20000"
SSLEnabled="true" scheme="https" secure="true"
keystoreFile="conf/.keystore"
keystorePass="changeit"
clientAuth="false" sslProtocol="TLS"
URIEncoding="UTF-8" compression="on"/>

然后您可以通过添加 transport-guarantee 强制您的应用程序始终使用 https标记为 web.xml结果是这样的:

<security-constraint>
<web-resource-collection>
<web-resource-name>Administrators</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Administrators</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>

您可以更改 transport-guarantee针对您定义的不同网络资源。因此,您可以保护网站的某些部分而不是其他部分。

最后在 server.xml 中有连接器不会强制您对所有应用程序使用 https。它只允许使用 https 连接器。

关于java - tomcat 中特定页面/url 模式的 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4281587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com