Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

1 Answer

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.