Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ssl 如何在Tomcat中使用虚拟主机时将HTTP流量重定向到HTTPS_Ssl_Redirect_Virtualhost_Tomcat9 - Fatal编程技术网

Ssl 如何在Tomcat中使用虚拟主机时将HTTP流量重定向到HTTPS

Ssl 如何在Tomcat中使用虚拟主机时将HTTP流量重定向到HTTPS,ssl,redirect,virtualhost,tomcat9,Ssl,Redirect,Virtualhost,Tomcat9,我需要配置Tomcat9服务器,将http重定向到https流量 我试过: 为http端口使用连接器,并具有指向安全连接器的redirectPort属性 在web.xml的底部包含一个安全约束,它适用于其他不使用虚拟主机的Tomcat服务器 连接器 <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" /> <Connector port="

我需要配置Tomcat9服务器,将http重定向到https流量

我试过:

  • 为http端口使用连接器,并具有指向安全连接器的redirectPort属性

  • 在web.xml的底部包含一个安全约束,它适用于其他不使用虚拟主机的Tomcat服务器

  • 连接器

    <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />
    
    <Connector 
            port="443"
            protocol="org.apache.coyote.http11.Http11AprProtocol"
            secure="true"
            scheme="https" 
            maxThreads="200" 
            SSLEnabled="true" 
            maxSpareThreads="75" 
            maxHttpHeaderSize="8192" 
            acceptCount="100"  
            enableLookups="false" 
            disableUploadTimeout="true"
            defaultSSLHostConfigName="example1.com">
                            <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
                            <SSLHostConfig hostName="example1.com">
                                            <Certificate 
                                            certificateKeystoreFile="www_example1_com.jks"
                                            certificateKeystorePassword="…” />
                            </SSLHostConfig>
                            <SSLHostConfig hostName="example2.com">
                                            <Certificate 
                                            certificateKeystoreFile="www_example2_com.jks"
                                            certificateKeystorePassword="…” />
                            </SSLHostConfig>
            </Connector>
    
    
    
    安全约束

    <security-constraint>
       <web-resource-collection>
          <web-resource-name>Entire Application</web-resource-name>
          <url-pattern>/*</url-pattern>
       </web-resource-collection>
       <user-data-constraint>
          <transport-guarantee>CONFIDENTIAL</transport-guarantee>
       </user-data-constraint>
    </security-constraint>
    
    
    整个应用程序
    /*
    保密的
    
    server.xml中的主机配置

          <!-- example1.com -->
          <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
    
            <Valve className="org.apache.catalina.valves.AccessLogValve" 
                   directory="logs"
                   prefix="localhost_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
          </Host>
    
          <!-- example2.com -->
          <Host name="example2.com" appBase="website-webapps" unpackWARs="true" autoDeploy="true">
    
            <Valve className="org.apache.catalina.valves.AccessLogValve" 
                   directory="website-logs"
                   prefix="website_access_log." 
                   suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
          </Host>
    
    
    
    • -工作
    • -工作
    • www.example2.com-不起作用
    • example2.com-不起作用

    我的服务器上的端口80未对外部通信开放,因此无法进行重定向。http通信没有到达服务器


    通过添加允许请求到达端口80的入站规则解决了此问题。

    端口80未对我的服务器上的外部通信开放,因此重定向永远不会发生。http通信没有到达服务器

    通过添加允许请求到达端口80的入站规则解决了这一问题