Reverse proxy to a tomcat service (folder name)

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/.
What I want is to acces my service through http://myApp.domain.com and
navigate my service AND whitout having http://myApp.domain.com/myApp/ !

I wrote this conf :

server {
server_name 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/, my browser rewrites this url to
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:
http://forum.nginx.org/read.php?2,201561,201561#msg-201561

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

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/;
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.

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”. 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/” "Mozilla/5.0

I don’t know why but it seems it requests
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:
http://forum.nginx.org/read.php?2,201561,201598#msg-201598

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/” "Mozilla/5.0

I don’t know why but it seems it requests
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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs