0

I want to configure nginx as a reverse proxy for different webapps hosted on a tomcat.

Basically, all requests to http://localhost:80/A/some/other/params (nginx is running on port 80) should be forwarded to http://localhost:8080/webappA/some/other/params (tomcat is running on port 8080, serving webappA).

I have tried this:

...
server {
    listen       80;
    server_name  localhost;
    root         /usr/share/nginx/html;

location /A/ {
    proxy_pass              http://localhost:8080/webappA/;
    proxy_set_header        X-Real-IP  $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        Host $http_host;
}
...

with no luck, since it forwards requests to http://localhost:8080/A//some/other/params/

I can't figure out from the proxy_pass docs how to have 1 location per local webapp. I don't want to deploy the webappA as root, since there will be multiple webapps in my tomcat instance. Thanks

EDIT:

I suspect there is also a problem also with the tomcat configuration, but can't find out where, since the proxyName and the proxyPort match the nginx' ones:

<Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000" 
                   proxyName="localhost"
                   proxyPort="80"
                   redirectPort="8443" />

The full nginx configuration is at this gist.

EDIT2: With further investigation with a minimal configuration, I learned that this proxying works.

My problem is instead related to add CORS headers, and the described way with ifs inside a location block is not working for me (nginx 1.6.2). I'll add cors headers from a tomcat filter.

3
  • Seems correct. How did you find out the forwarded request ? Mar 17, 2015 at 10:52
  • It's printed by tomcat as the 404 error report page.
    – mox601
    Mar 17, 2015 at 10:53
  • That should not happen, post your full nginx configuration. Mar 17, 2015 at 11:02

0

You must log in to answer this question.

Browse other questions tagged .