With my past project, I have Nginx serving static files as well as being a reverse proxy for Tomcat (backend written in Java). There was no Cloudflare or other CDN.

With my current project, I have Cloudflare plus Nginx plus Tomcat. Does it make sense to remove Nginx from the picture and use Tomcat for static files, given that static files will be mostly served by Cloudflare?

  • Are you planning to move the static files to tomcat and use it as the origin server for them? Oct 15, 2021 at 12:35
  • @Stephon Ostermiller. Exactly. Not yet planning, but want to know if it makes sense.
    – Yuriy N.
    Oct 15, 2021 at 13:29
  • 1
    CloudFlare caches static content in regional servers, so yes, that would be redundant. You might have more difficulty with analytics too and logging things like IPs if you don't forward header info properly from one Nginx server to the next. I'd really recommend removing your Nginx in that scenario if you don't need to proxy a backend server on a specific port.
    – dan
    Oct 15, 2021 at 14:19
  • If you were to remove Nginx would you put your static files onto your Tomcat server? Oct 16, 2021 at 0:19
  • @StephenOstermiller Yes, I would put static files onto Tomcat. It will reduce deployment complexity, but I care about performance more, hence the question.
    – Yuriy N.
    Oct 16, 2021 at 18:20

2 Answers 2


Nginx has a few important functions:

  1. Sets cache control headers (such as expiry and etags)
  2. Keeps frequently accessed static files in memory
  3. Sets up virtual hosts allowing multiple domains to be hosted on the same server
  4. Swaps the port number of the tomcat server to the defaults: 80 and 443.
  5. Handles SSL/TLS encryption and certificates for HTTPS

I believe that Tomcat serves etags for all requests. You can configure appropriate expires headers with Tomcat: https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/filters/ExpiresFilter.html

I do not believe there is any configuration available in Tomcat to create a in-memory cache of frequently accessed files. Since the static files will mostly be served by Cloudflare, that is not functionality that would be important any longer.

If this is your only domain hosted on that server, then the virtual hosting capabilities of nginx won't be needed. However, if you are hosting other content for other domains, you may still need to run Nginx.

If you get rid of Nginx you can run Tomcat on port 80 and 443. If you have other backend servers for other content, you may still need Nginx.

Tomcat can be configured with certificates for HTTPS: https://tomcat.apache.org/tomcat-8.5-doc/ssl-howto.html

In summary: it may be possible to get rid of Nginx without hurting performance, but doing so requires that all your content for all your domains can be served by Tomcat. There are several things that you may need to reconfigure on Tomcat.


Finally, I end up with the same configuration i.e. CloudFlare - Nginx - Tomcat. The main reason is that my application is still under active development and js/css files are updated frequently. Every time something is updated I purge the Cloudflare cache. Without Cloudflare, Nginx is obviously better for serving static files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.