0

I have multiple webapps on a server, each on a seperate port:

http://localhost:8080
http://localhost:8081

Now, I've tried to use nginx in the front as a proxyserver. Goal is, to use webapps.local.domain/mywebapp1 and webapps.local.domain/mywebapp2 instead of above URLs. I tried this, but it did'nt worked:

server {
        listen   80;
        server_name  webapps.local.domain;

        access_log  /var/log/nginx/webapps.local.domain-access.log;

location /mywebapp1 {
proxy_pass       http://127.0.0.1:8080;
proxy_redirect   http://127.0.0.1:8080 /mywebapp1/;

}
}

This loads the HTML of the first page of the webapp. But no CSS, images and anything else. Where is my fault?

Thomas Deutsch
  • 199
  • 2
  • 9
  • Check the text of the first page. It will include references to the missing CSS and image files. I think, there will be wrong URLs there, from which you'll decipher what went wrong. – minaev Dec 18 '11 at 13:38

1 Answers1

1

You have to use this block:

location /mywebapp1 {
   rewrite /mywebapp1(.*)$ $1 break;
   proxy_pass http://127.0.0.1:8080;
}

proxy_redirect will send to your browser HTTP code 301, permanent redirect to 127.0.0.1:8080, which is not your intence.

Jan Marek
  • 2,120
  • 1
  • 13
  • 14
  • rewrite /mywebapp1(.*)$ $1 break; gave me an Error 500. Change it to rewrite /mywebapp1/(.*)$ $1 break; solves the Error 500, but now the site looks same: no images, no css. It looks like the browser tries to load css from 127.0.0.1:8080, which does not work. – Thomas Deutsch Dec 16 '11 at 10:30
  • @ThomasDeutsch: Try to inspect the source code of your loaded web page, if there is not a URL's with address 127.0.0.1:8080. – Jan Marek Dec 19 '11 at 12:09