Configuring nginx for both Rails and Tomcat

This is easy to do but I had a few missteps in setting up nginx with both Rails and Tomcat so it is worthwhile documenting what I did. I have two cooking and recipe web portals, an older one written in Java ( and a newer one that uses the USDA nutritional database that runs on Rails ( These are low volume sites so I wanted to run both on a single inexpensive VPS.

Usually I run a few virtual domains on one Tomcat instance (requires a simple mapping in conf/server.xml between virtual domain names and subdirectories of $TOMCAT/webapps) but in this case, I only need to add a single virtual domain for my Java web app on a system that is already configured for Rails. So, no changes to server.xml are required and I deployed to $TOMCAT/webapps/ROOT. Then, the only thing left to do was add a section in my nginx.conf file for Tomcat running on port 8080:
    server {
listen 80;
root /usr/local/tomcat/webapps/ROOT;

access_log off;
rewrite_log on;

location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Both my wife and I are very good cooks, and writing two cooking/recipe web apps has been a fun hobby.


  1. Curious why you chose Ruby for your newer implementation. Just looking for a change of pace or were there technical reasons?

  2. Hello Derek,

    Partially as a change of pace, but I find that I can develop and maintain Rails web applications with much less effort than Java. That said, I still very much like the Java platform when runtime performance is more important than reducing the expense of development.


  3. Just wanted to add a comment - the nginx.conf file worked fine.

    You saved me a lot of hassle, because previously I was following another recipe for an nginx.conf file which was more complicated:

    Also, that other nginx.conf file wasn't serving my static content (CSS, JavaScript) so it clearly was incorrect.

    Your nginx.conf was shorter and simpler - and correct. Thanks!


Post a Comment

Popular posts from this blog

DBPedia Natural Language Interface Using Huggingface Transformer

Custom built SBCL and using spaCy and TensorFlow in Common Lisp

I have a new job helping to build a Knowledge Graph at Olive AI