How to force HTTPS on a Tomcat application

Forcing HTTPS on a Tomcat application is one of the most important steps when you are publishing a public web app, especially when the site handles logins, contact forms, cookies, or any other sensitive data. In a managed hosting environment with Plesk and a Java hosting setup such as My App Server, you usually want traffic to reach your application securely through HTTPS at all times, while any plain HTTP request is redirected automatically.

The exact method depends on how your Tomcat instance is running. In many cases, the best approach is to terminate SSL at the web server layer and redirect HTTP to HTTPS before requests reach the application. If your Tomcat is exposed directly, you can also enforce HTTPS using Tomcat configuration such as a security constraint or a redirect valve. The right choice depends on your hosting setup, how your domain is configured, and whether you are using Plesk, Apache, or a private JVM with Apache Tomcat.

Why forcing HTTPS matters for Tomcat applications

HTTPS protects the connection between the browser and your application by encrypting data in transit. For Tomcat-based apps, this is especially important when the application uses sessions, authentication, API calls, file uploads, or form submissions.

Forcing HTTPS also helps with:

  • protecting user credentials and session cookies
  • avoiding mixed-content issues when browsers block insecure assets
  • improving trust and compatibility with modern browsers
  • supporting SEO and cleaner canonical URLs
  • reducing the chance that users stay on an insecure HTTP version of your site

If your hosting platform provides a control panel such as Plesk, you can usually manage the certificate and redirection without touching the application code. This is often the simplest and safest option for Java hosting and Tomcat hosting setups.

Recommended way to force HTTPS in a hosting environment

In a typical managed hosting setup, the most practical solution is:

  1. install and activate an SSL/TLS certificate for the domain
  2. make sure the site is reachable on HTTPS
  3. redirect all HTTP traffic to HTTPS at the web server or control panel level
  4. verify that the Tomcat application generates secure links and cookies correctly

This approach keeps the redirect outside the application, which is usually easier to maintain. It also avoids unnecessary logic inside the Java app when Plesk or Apache can handle the redirect centrally.

How to force HTTPS on a Tomcat application in Plesk

If your Tomcat application runs through a hosting control panel such as Plesk, the cleanest method is often to configure HTTPS at the domain level and then use a redirect rule. In many cases, Plesk can help you manage the certificate and web server settings for the domain where the Tomcat app is published.

Step 1: Install or assign an SSL certificate

Before you redirect anything, make sure the domain has a valid certificate installed. Without a working certificate, visitors who are redirected to HTTPS will see browser errors.

Check that:

  • the certificate matches the domain name
  • the certificate chain is complete
  • the certificate is not expired
  • the domain resolves to the correct hosting account

If you use a control panel, this is usually done from the SSL/TLS or certificates area. After installation, test the HTTPS version of the site directly before enabling the redirect.

Step 2: Confirm that Tomcat is reachable over HTTPS

Make sure the application opens correctly on the secure URL. If your setup uses Apache in front of Tomcat, Apache may serve the certificate and forward requests to the Java application. If your Tomcat is running on a private JVM through My App Server, the service may be exposed through the platform’s configured web access path.

At this stage, verify:

  • the main page loads on https://
  • login pages and forms work without browser warnings
  • static assets such as CSS and images are also loaded securely
  • session cookies are marked as secure if the app supports it

Step 3: Add the HTTP to HTTPS redirect

Once HTTPS works, configure a permanent redirect from HTTP to HTTPS. The redirect should apply to all paths, not only the homepage. This ensures that old bookmarks, external links, and plain HTTP requests are automatically upgraded.

In a Plesk-managed environment, the redirect is often added in the domain’s hosting settings or via web server directives. The exact interface depends on the hosting platform, but the goal is always the same: any request to http://yourdomain.example should be redirected to https://yourdomain.example.

If your hosting provider allows custom Apache directives, you can use a server-side redirect there. For example, a common approach is to redirect all HTTP traffic with a 301 status code. A 301 redirect is preferred because it tells browsers and search engines that the HTTPS URL is the permanent version.

Forcing HTTPS in Tomcat configuration

When you need the application itself to enforce secure access, Tomcat can do this with a security constraint. This is useful if you cannot rely entirely on the web server layer, or if you want the application to reject insecure requests internally.

Use a security constraint in web.xml

You can require confidential transport for specific URL patterns by adding a security constraint in the application’s deployment descriptor. This is common for login pages, admin paths, and form endpoints.

A typical approach is to secure the entire application by requiring HTTPS for all URLs. Conceptually, the configuration tells Tomcat that the matched resources must only be accessed over a secure channel.

Example structure:

  • define a security-constraint
  • set the URL pattern to /* or a more specific path
  • add a user-data-constraint
  • set the transport guarantee to CONFIDENTIAL

This method is appropriate when you want Tomcat to enforce HTTPS regardless of where the request came from. However, in many hosted environments, redirecting at Apache or Plesk is still simpler and less error-prone.

Make sure Tomcat knows the original protocol

If HTTPS is terminated before Tomcat, the application may need to know that the user connected securely through a proxy or front-end server. Otherwise, generated links may still appear as HTTP, or the app may create cookies and redirects incorrectly.

In Apache + Tomcat setups, this is typically handled by forwarding headers such as:

  • X-Forwarded-Proto
  • X-Forwarded-Host
  • X-Forwarded-Port

Your application or Tomcat connector must be configured to trust and interpret those headers correctly. If this is not set up, your app may redirect in a loop or keep sending users back to the non-secure URL.

Common redirect methods for Tomcat-based apps

There are several ways to force HTTPS, and the best one depends on your deployment model.

Redirect at the web server layer

This is usually the preferred option when Apache sits in front of Tomcat. The web server handles the request first, so it can redirect plain HTTP before the request reaches the Java app. This keeps the application simpler and reduces the chance of redirect loops.

Use this when:

  • your domain is managed through Plesk
  • Apache serves the public URL
  • Tomcat runs behind Apache or through the hosting platform

Redirect in Tomcat

Use Tomcat configuration when the app is exposed directly or when you want application-level enforcement as a backup. This is a good option for hosted Java applications where the Tomcat instance is managed through a private JVM and you want the application itself to require secure transport.

Redirect in the application code

You can also force HTTPS from within the Java application, but this is usually the least preferred method because it spreads transport logic into code that should focus on application behavior. It may still be useful for very specific routes or custom requirements, but for most Tomcat hosting setups, control panel or web server redirects are better.

Best practices for secure Tomcat hosting

When you enable HTTPS, make sure the rest of the application is aligned with it. A redirect alone is not enough if the app still generates insecure links or stores cookies without secure flags.

  • use a valid certificate for the correct domain
  • redirect all HTTP requests to HTTPS with a 301 status code
  • avoid hard-coded http:// links in templates or Java code
  • set cookies as Secure when appropriate
  • verify that the app supports HTTPS behind a reverse proxy
  • update canonical URLs and sitemap entries to use HTTPS
  • test forms, sessions, and logins after the change

If your app uses third-party services, update callback URLs, webhook endpoints, and OAuth redirect URLs so they point to the secure version of the site. A common issue after forcing HTTPS is that external services still call the old HTTP address.

How to avoid redirect loops

Redirect loops are one of the most common problems when forcing HTTPS in a Tomcat application. They happen when the application thinks the request is HTTP even though the browser is already using HTTPS, usually because SSL is terminated upstream and Tomcat is missing the proxy headers.

To avoid this:

  • do not redirect both at the proxy and inside the app without checking the flow
  • make sure forwarded headers are configured correctly
  • verify the scheme seen by the application
  • check that your redirect applies only to plain HTTP requests

If you are using a hosting platform with My App Server, check how the service is published and whether Apache or another front-end component is handling TLS termination. That distinction is important when you troubleshoot redirects.

Tomcat configuration example: forcing secure transport

If you decide to enforce HTTPS inside the application, the usual Tomcat approach is a security constraint. The structure is simple and works well for all URLs or selected paths.

Conceptually, the configuration should:

  • match the URLs you want to protect
  • declare that the transport must be confidential
  • allow Tomcat to send insecure requests to the HTTPS version

For a full-site enforcement, apply the rule to all application paths. For a mixed site, secure only the login, account, checkout, or admin sections. This can reduce overhead if part of the application is intentionally public and non-sensitive, although for most hosted applications it is cleaner to serve everything over HTTPS.

Testing your HTTPS setup

After you configure the redirect, test the site carefully. A secure redirect is only successful if every major user flow works end to end.

Check the following:

  • HTTP redirect — opening the plain HTTP URL should jump to HTTPS automatically
  • HTTPS certificate — browser shows a valid secure connection without warnings
  • page assets — no mixed-content warnings in the browser console
  • forms and logins — authentication and submission flows continue to work
  • session persistence — users remain logged in across secure requests
  • subpages — deep links and not just the homepage redirect properly

If something fails, inspect whether the issue is in the certificate, the redirect rule, the proxy headers, or the Tomcat application itself. In a managed hosting environment, it is often easiest to isolate each layer one by one.

Special notes for My App Server and private JVM hosting

If you are using a Java hosting setup with My App Server, you typically manage a private JVM and Apache Tomcat through the control panel. This is convenient for WAR, JSP, and servlet applications because you can control the application runtime without needing a full enterprise application server stack.

For HTTPS, this usually means:

  • the domain certificate is managed separately from the Java app
  • the Tomcat service may be started and stopped from the panel
  • the redirect is often best handled at the web server or domain level
  • the app should be tested after deployment to ensure it respects secure URLs

If you install a ready-made Tomcat version or upload a custom one, always confirm how the service is exposed before you configure the redirect. The right method for forcing HTTPS depends on whether the public connection terminates at Apache, at a proxy, or directly at Tomcat.

When to choose each method

Use the following guidance to decide the best approach for your Tomcat application:

  • Plesk or Apache redirect — best for most hosted websites and public Java apps
  • Tomcat security constraint — useful when the application itself must require secure transport
  • Application code redirect — only for special cases or custom logic

For most hosting customers, the most maintainable setup is to manage the certificate and redirect in the control panel, then verify that Tomcat honors the secure request correctly.

FAQ

Can I force HTTPS without changing the Tomcat application code?

Yes. In many hosting setups, you can force HTTPS at the web server or control panel level, which is usually the best option. This keeps redirect logic outside the Java application and is easier to maintain.

Should I redirect only the homepage or the whole site?

Redirect the whole site. Every HTTP URL should move to its HTTPS equivalent, including subpages, forms, and API endpoints. Redirecting only the homepage leaves other pages accessible over HTTP.

Is a 301 redirect the right choice?

Yes, in most cases. A 301 redirect tells browsers and search engines that the HTTPS version is permanent. That is the standard choice for forcing secure access.

What if Tomcat still generates http links after I enable HTTPS?

That usually means Tomcat does not know that the original request was secure. Check your proxy headers, especially X-Forwarded-Proto, and confirm that your application or connector is configured to trust the front-end server.

Can I force HTTPS for only part of my application?

Yes. You can protect only selected URL patterns, such as login or admin paths, by using a Tomcat security constraint. However, for public-facing sites, it is usually better to serve everything over HTTPS.

Why do I get a redirect loop after enabling HTTPS?

This usually happens when both the proxy and the application try to redirect, or when Tomcat does not see the request as secure. Review the redirect rule and the forwarded headers to make sure only plain HTTP is redirected.

Conclusion

Forcing HTTPS on a Tomcat application is best done with a combination of a valid SSL certificate, a clean HTTP to HTTPS redirect, and correct proxy or Tomcat configuration. In a hosting environment with Plesk and My App Server, the most practical setup is usually to handle the redirect at the domain or Apache level and then verify that the Java application works correctly over HTTPS.

When implemented properly, HTTPS improves security, user trust, and compatibility across the whole Tomcat application. It also helps keep your deployment simple and maintainable, which is especially important for managed Java hosting, JSP hosting, servlet hosting, and private JVM setups.

  • 0 Users Found This Useful
Was this answer helpful?