How to redirect from HTTP to HTTPS on Tomcat Server
On this page, we will learn how to redirect an application from HTTP to HTTPS on Tomcat Server automatically. But before directly jumping to the configuration, make sure you have installed and configured the self-signed SSL on the Tomcat server.
And if SSL is not configured yet, you can take help from our previous blog on How to configure SSL/HTTPS on Tomcat Server.
Step 1: Open the server.xml
file from ~{Tomcat-Installation-Directory}/conf
directory and set the redirect port to the HTTPS connector port for the HTTP connector.
<Connector
port="8090"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
/>
Step 2: Add the below configuration in ~{Tomcat-Installation-Directory}/conf/web.xml
file but make sure to add it after all the Servlet mapping tags.
<security-constraint>
<web-resource-collection>
<web-resource-name>All Web Application</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
Step 3: Now restart the Tomcat server and hit http://localhost:8090/docs/ on your browser and it will automatically redirected to https://localhost:8443/docs/.
References
Similar Posts
- The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
- Maven- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
- IntelliJ IDEA- Undo and Redo Shortcut Keys
- How to create new role and grant permission to role in JasperReports Server
- How to remove vertical line from editor pane in IntelliJ IDEA