简体   繁体   中英

Deploy WAR to Tomcat 8 with SSL

I have developed a web application using Intellij IDEA and I have used the IDE's Build functions to generate a WAR file. My application's web.xml contains the following code segment:

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

so that every page in my application is secured with SSL.

I have also used keytool and I have enabled HTTPS on port 8443 in conf/server.xml as described on the official Tomcat documentation.

When I launch the project from the IDE it runs just fine with SSL enabled on port 8443 but if I place the .war file in tomcat's webapps directory, restart the server and navigate to https://localhost:8443/testApplication , I get an ERR_TIMED_OUT error.

If I edit the deployed application's web.xml and remove the above segment, thus allowing the application to run on the default port 8080, the application runs smoothly.

So, with Intellij both ports work, but if I manually deploy the application only 8080 works properly. Have I missed something?

It seems that the difference between IntellijIdea deployment and manual is the context path of your application. Intellij idea run the application by default as root application so yo can access without context path.

Try to modify url-pattern to this /testApplication/* on your web.xml, build your war artifact and deploy it manually to Tomcat

<web-resource-collection>
    <web-resource-name>sslTestApp</web-resource-name>
    <url-pattern>/testApplication/*</url-pattern>
</web-resource-collection>

Just in case someone else might be facing the same issue, the solution was to explicitly set the key's location and the key alias in server.xml like this:

<Connector port="8443" protocol="HTTP/1.1"
           maxThreads="150" SSLEnabled="true" scheme="https" secure="true" keystoreFile="C:\mykeystore"
           keyAlias="mykey"
           clientAuth="false" keystorePass="yourPassword" sslProtocol="TLS" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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