简体   繁体   English

无法将 http 重定向到 https

[英]Not able to redirect http to https

Please look into my server.xml ;请查看我的server.xml I am not able to redirect port 8019 to https (port 443).我无法将端口 8019 重定向到 https(端口 443)。 I tried various examples on the web but I still cannot get it working.我在 web 上尝试了各种示例,但仍然无法正常工作。 Could anyone help me with what is wrong with my server.xml ?谁能帮我解决我的server.xml出了什么问题?

<Connector port="8019" protocol="HTTP/1.1"
           connectionTimeout="100000"
           redirectPort="443" />

<Connector port="443" maxHttpHeaderSize="8192" SSLEnabled="true"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true" clientAuth="false"
keystoreFile="C:\zenfortecertificate\3_zensar_com.pfx" keystorePass="[my password]" keystoreType="PKCS12"
sslEnabledProtocols="TLSv1.2" 
ciphers="TLS_RSA_WITH_AES_256_CBC_SHA256,
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384,
TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384"/>

<Connector port="8019" protocol="AJP/1.3" redirectPort="443" />

<Engine name="Catalina" defaultHost="zenforte-stg.zensar.com">
  <Host name="localhost"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">
    [...]
  </Host>
  <Host name="zenforte-stg.zensar.com"  appBase="zen_webapps"
        unpackWARs="true" autoDeploy="true"/> 
</Engine>

There are a few problems with your server.xml .您的server.xml存在一些问题。 Some of them have to do with your actual question, others are just things you might want to think about.其中一些与您的实际问题有关,其他只是您可能想要考虑的事情。

First, you have two <Connector> elements on the same port (8019):首先,您在同一端口 (8019) 上有两个<Connector>元素:

<Connector port="8019" protocol="HTTP/1.1" connectionTimeout="100000" redirectPort="443" />

and

<Connector port="8019" protocol="AJP/1.3" redirectPort="443" />

So the first thing to do is to pick a connector and remove the other one.因此,首先要做的是选择一个连接器并移除另一个连接器。 If you want to use the AJP protocol with your reverse-proxy or load balancer, then keep the AJP one.如果您想将 AJP 协议与反向代理或负载均衡器一起使用,请保留 AJP 协议。 Otherwise, use the HTTP one.否则,使用 HTTP 之一。

The key to redirecting HTTP -> HTTPS is the redirectPort in your non-secure <Connector> (on port 8019, whichever one AJP/HTTP you choose).重定向 HTTP -> HTTPS 的关键是非安全<Connector>中的redirectPort (在端口 8019 上,无论您选择哪一个 AJP/HTTP)。 But the redirect doesn't happen unless your application asks for it.但是除非您的应用程序要求重定向,否则不会发生重定向。 In order to do that, you need this in your application's WEB-INF/web.xml :为此,您需要在应用程序的WEB-INF/web.xml

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

This tells the container (Tomcat) that the application expects "confidential" communication and it will automatically redirect any non-confidential (ie insecure) requests to the confidential (ie encrypted) protocol on the other port (https/443).这告诉容器(Tomcat)应用程序需要“机密”通信,它会自动将任何非机密(即不安全)请求重定向到另一个端口(https/443)上的机密(即加密)协议。

Some other considerations:其他一些考虑:

  1. Your connectionTimeout of 100 seconds is a long time .您的connectionTimeout为 100 秒是很长的时间 You probably want that to be much lower otherwise clients can tie-up your server without accomplishing any work.您可能希望它低得多,否则客户端可以在不完成任何工作的情况下占用您的服务器。
  2. Your <Connector> contains all of your secure configuration.您的<Connector>包含您的所有安全配置。 Modern Tomcats use a <SSLHostConfig> for all that configuration.现代 Tomcat 使用<SSLHostConfig>进行所有配置。 This suggests an old configuration with a new server or, worse, an old server.这表明旧配置带有新服务器,或者更糟糕的是,旧服务器。 You should try to upgrade to the latest server and use the latest configuration style.您应该尝试升级到最新的服务器并使用最新的配置样式。 The newer configuration style gives you greater control over the configuration and makes it clearer what is happening.较新的配置样式使您可以更好地控制配置并使正在发生的事情更加清晰。 (For example, if you want to use RSA + ECDSA, the configuration is more explicit using <SSLHostConfig> + <Certificate> than just specifying the keystore and hoping for the best. (例如,如果您想使用 RSA + ECDSA,则使用<SSLHostConfig> + <Certificate>的配置比仅指定密钥库并希望获得最好的配置更加明确。
  3. If you aren't using the "localhost" <Host > in your configuration, remove it.如果您没有在配置中使用“localhost” <Host >,请将其删除。 Even better, if you don't have any other <Host> s defined, just allow the "localhost" one to cover everything.更好的是,如果您没有定义任何其他<Host> ,只需允许“localhost”覆盖所有内容。 This makes your configuration less customized from the default, and therefore you have fewer changes to maintain from the stock server.xml .这使得您的配置从默认值中定制的更少,因此您需要从库存server.xml维护的更改更少。
  4. Specifying disableUploadTimeout="true" doesn't have any effect unless you also specify connectionUploadTimeout指定disableUploadTimeout="true"没有任何效果,除非您还指定connectionUploadTimeout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM