nginx and tomcat in eclipse – multiple apps

I’m running Tomcat with Nginx as a load balancer. And too keep all the redirects etc consistent, I am also running it in front of Eclipse.

Tomcat in Eclipse seems to fail it you try to configure multiple virtual hosts. So I need to configure each app to run from a different url in Eclipse. e.g. the server.xml looks like:

  <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
    <Context docBase="app1" path="/" reloadable="true" source="org.eclipse.jst.jee.server:app1"/>
    <Context docBase="app2" path="/app2" reloadable="true" source="org.eclipse.jst.jee.server:app2"/>
  </Host>

Problem is when I proxy to it, I can’t get it to use the code in the subfolder app2. It serves it from the root. And I can’t seem to get a rewrite to fix it either…

Nginx config has…

location ~ \.(do|jsp)$ {
    #rewrite ^(.*) $1 break;
    proxy_pass              http://127.0.0.1:8080;
    proxy_set_header        Host $http_host;
    proxy_set_header        X-Real-IP $remote_addr;
}

What I want to do is:

    proxy_pass              http://127.0.0.1:8080/app2;

But that’s not allowed it seems.

I know how to fig it with a server. But Eclipse seems to only work with a single virtual host. So I’m stuck with folders…

What am I missing?

Answer

Did you read the docs ?

Syntax:  proxy_pass URL;
Default: —
Context: location, if in location, limit_except

Sets the protocol and address of a proxied server and an optional URI to which a location should be mapped. As a protocol, “http” or “https” can be specified. The address can be specified as a domain name or IP address, and an optional port:

proxy_pass http://localhost:8000/uri/;

[…]

In some cases, the part of a request URI to be replaced cannot be determined:

When location is specified using a regular expression.
In this case, the directive should be specified without a URI.

When the URI is changed inside a proxied location using the rewrite directive, and this same configuration will be used to process a request (break) :

location /name/ {
    rewrite    /name/([^/]+) /users?name=$1 break;
    proxy_pass http://127.0.0.1;
}

In this case, the URI specified in the directive is ignored and the full changed request URI is passed to the server.

[ …]

Attribution
Source : Link , Question Author : PrecisionPete , Answer Author : Xavier Lucas

Leave a Comment