# Reverse proxy to a tomcat service (folder name)

**URL:** <https://www.ruby-forum.com/t/reverse-proxy-to-a-tomcat-service-folder-name/207539>\
**Category:** NGINX\
**Created:** [May 27, 2011, 4:59pm UTC](https://www.ruby-forum.com/t/reverse-proxy-to-a-tomcat-service-folder-name/207539 "2011-05-27T16:59:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [May 27, 2011, 4:59pm UTC](https://www.ruby-forum.com/t/reverse-proxy-to-a-tomcat-service-folder-name/207539/1 "2011-05-27T16:59:57Z")

</div>

Hello,

I am breaking my head against the wall since his morning on this issue  
maybe you can help me.

I have a single physical server hosting tomcat WARs and also other  
standalone services. I use subdomains and Nginx to route to the  
requested service.  
Tomcat append to URIs the name of the deployed WAR. For example, if I  
deploy myApp.war on my tomcat server, I can access it through  
[http://mydomain.com:8080/myApp/](http://mydomain.com:8080/myApp/).  
What I want is to acces my service through [http://myApp.domain.com](http://myApp.domain.com) and  
navigate my service AND whitout having [http://myApp.domain.com/myApp/](http://myApp.domain.com/myApp/) !

I wrote this conf :

server {  
server\_name [myapp.domain.com](http://myapp.domain.com);  
root /var/lib/tomcat7/webapps/myapp;  
access\_log /var/log/nginx/myapp.domain.com\_access.log;  
error\_log /var/log/nginx/myapp.domain.com\_error.log;

```
    location / {
            proxy_pass http://localhost:8080/myapp;
            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;  
}

```
    location /myapp {
            proxy_pass http://localhost:8080/myapp;
            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;  
}  
}

If I access [http://myapp.domain.com/](http://myapp.domain.com/), my browser rewrites this url to  
[http://myapp.domain.com/myapp/](http://myapp.domain.com/myapp/). I would like to avoid the /myapp/  
repeated.

Do you have hints or comments to help me ?

Thanks a lot

Posted at Nginx Forum:

> **[Reverse proxy to a tomcat service (folder name)](https://forum.nginx.org/read.php?2,201561,201561#msg-201561)**
>
> Hello, I am breaking my head against the wall since his morning on this issue maybe you can help me. I have a single physical server hosting tomcat WARs and also other standalone services. I use subdomains and Nginx to route to the requested service....

---

<div class="post-metadata">

**Author:** ![kheraud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8c91f0/32.png) [@kheraud](https://www.ruby-forum.com/u/kheraud)\
**Post date:** [May 27, 2011, 5:11pm UTC](https://www.ruby-forum.com/t/reverse-proxy-to-a-tomcat-service-folder-name/207539/2 "2011-05-27T17:11:43Z")

</div>

On Fri, May 27, 2011 at 10:59:41AM -0400, kheraud wrote:

> [http://mydomain.com:8080/myApp/](http://mydomain.com:8080/myApp/).
> 
> ```
> proxy_pass http://localhost:8080/myapp;
> 
> ```
> 
> repeated.
> 
> Do you have hints or comments to help me ?

Probably this:

location / {  
proxy\_pass [http://myapp.domain.com:8080/myapp/](http://myapp.domain.com:8080/myapp/);  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
sub\_filter /myapp/ /;  
}

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![kheraud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8c91f0/32.png) [@kheraud](https://www.ruby-forum.com/u/kheraud)\
**Post date:** [May 27, 2011, 6:27pm UTC](https://www.ruby-forum.com/t/reverse-proxy-to-a-tomcat-service-folder-name/207539/3 "2011-05-27T18:27:10Z")

</div>

Thank you for the hint,

It seems to work (for the first page) but in fact it leads to some  
errors… You added “/” to “proxy\_pass [http://localhost:8080/myapp](http://localhost:8080/myapp)”. But  
I ommitted it after having seen that it leads to the following mistakes  
on the tomcat side :

The requested resource (/dev01-portal//j\_spring\_security\_check) is not  
available.

The access log is :  
[27/May/2011:18:23:32 +0200] “POST /dev01-portal/j\_spring\_security\_check  
HTTP/1.1” 404 441 “[http://dev01-portal.appssalon.com/](http://dev01-portal.appssalon.com/)” "Mozilla/5.0

I don’t know why but it seems it requests  
[http://localhost:8080/dev01-portal//j\_spring\_security\_check](http://localhost:8080/dev01-portal//j_spring_security_check).

Do you know where it comes from ?

Thanks again for the help

Posted at Nginx Forum:

> **[Re: Reverse proxy to a tomcat service (folder name)](https://forum.nginx.org/read.php?2,201561,201598#msg-201598)**
>
> Hello, I am breaking my head against the wall since his morning on this issue maybe you can help me. I have a single physical server hosting tomcat WARs and also other standalone services. I use subdomains and Nginx to route to the requested service....

---

<div class="post-metadata">

**Author:** ![kheraud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8c91f0/32.png) [@kheraud](https://www.ruby-forum.com/u/kheraud)\
**Post date:** [May 27, 2011, 6:33pm UTC](https://www.ruby-forum.com/t/reverse-proxy-to-a-tomcat-service-folder-name/207539/4 "2011-05-27T18:33:21Z")

</div>

On Fri, May 27, 2011 at 12:26:47PM -0400, kheraud wrote:

> The access log is :  
> [27/May/2011:18:23:32 +0200] “POST /dev01-portal/j\_spring\_security\_check  
> HTTP/1.1” 404 441 “[http://dev01-portal.appssalon.com/](http://dev01-portal.appssalon.com/)” "Mozilla/5.0
> 
> I don’t know why but it seems it requests  
> [http://localhost:8080/dev01-portal//j\_spring\_security\_check](http://localhost:8080/dev01-portal//j_spring_security_check).
> 
> Do you know where it comes from ?

It seems you have two locations:

location / {  
location /dev01-portal {

You need just one:

location / {

–  
Igor S.
