Nginx + Tomcat7 for single webapp and multiple alias domain

Mikhail Mazursky ash2kk at
Thu Sep 15 09:30:28 UTC 2011

2011/9/14 tm1978 <nginx-forum at>:
> I am thinking about using NGINX instead of Apache to deliver a Tomcat7
> webapp on Port :80 to the enduser.
> I have the following requirements:
> 1. There is a single  web-app in the root with any urls (its own
> internal urlrewriting). It has various URLs pointing to it for several
> languages (and partially other content)
> 2. Another admin-webapp exists
> My questions are:
> (a) would it be a good idea to use NGINX a without  Apache Http server,
> just with Apache Tomcat7 ?
> (b) how can I set this up so that the Tomcat App always know the domain
> name the user was using when calling the page?
> (c) will the tomcat app still be able to know the IPs of every user?

For this you will have to setup a RemoveIpValve [1] in your
context.xml/server.xml/context.xml.default like this:

        protocolHeader="X-Forwarded-Proto" />

In nginx you may use configuration provided by cfsego but don't forget
to add X-Forwarded-Proto if you use https on nginx. Also you may
remove X-Real-IP header because it's not used in this setup:

>>> location / {
>>>     proxy_pass;
>>>     proxy_set_header        Host $host;
>>>     proxy_set_header         $remote_addr;

proxy_set_header        X-Forwarded-Proto $scheme;

>>>     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
>>> }

This way Tomcat will be aware of https and will use secure cookies for sessions.


> Thanks!
> Tobias

More information about the nginx mailing list