0

I need to configure Nginx as a reverse proxy for Tomcat. The problem is when I try to access the web application through a subdomain (myapp.domain.com), in this case is displayed Tomcat webapps root, not myapp.

Nginx conf

server {
    listen 80;

    root /usr/share/tomcat/webapps/myapp;
    index index.php index.html index.htm;

    access_log off;

    server_name myapp.domain.com;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;
      proxy_pass http://127.0.0.1:8181;
    }
}

I tried adding this line in Tomcat's server.xml, inside the Host tag:

<Context path="" docBase="myapp" debug="0" reloadable="true" />

but in this way myapp became the default one and is "always" loaded, even if trying to access webapps root

0

If I understand your problem correctly, you need to give consideration to how Tomcat is interpreting the 'Host' header, by configuring virtual hosting for it (see https://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html).

Either that, or do not have the Context tag in server.xml, and change proxy_pass to:

proxy_pass http://127.0.0.1:8181/myapp

| improve this answer | |
  • Changing proxy_pass to 127.0.0.1:8181/myapp causes this problem: I get an error message on the browser "Cookies Disabled" – csaffi Apr 7 '15 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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