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

I have two machines, and they are served by a master machine. The master machine defines the first machine 10.10.0.59

server {
        listen 80;
        client_max_body_size 200M;
        server_name localhost 127.0.0.1;
        server_name_in_redirect off;

location / {
        proxy_pass http://10.10.0.59;
        proxy_redirect default;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ^~ /dev/ {

        proxy_pass http://10.10.0.56;
        proxy_redirect default;
        proxy_set_header Host $http_host;
        rewrite /dev/(.*) /$1 break;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

The dev machine is 10.19.9.56 and I need to add (most likely) /dev/ to the url path, so that I can browse it by http://public_domain/dev/.....

Each of these machines has several apps running.

With this new rule, I can go on by http://public_domain/dev/app1/ but all the links on that page will point to, for example, http://public_domain/app1/login which is server#1.

What else is wrong? Thanks.

Should I setup a new server clause? If I do, do I need to open a different port because the these two location blocks are inside the same server clause and listening on 80.

Thanks.

share|improve this question

2 Answers 2

The issue is the trailing / on your proxy_pass directives. That tells proxy_pass to replace the part of the url that matched the location (/dev) with the provided path (/). It doesn't make a difference in your location / because it's replacing / with /. If you just replace your current line with

proxy_pass http://10.10.0.59;

Then it will not process the url before passing it to the backend.

share|improve this answer
    
Thank you. I've just updated my post. Do I need a different server block? I have only one and I've tried to rewrite. –  Daniel Huger Jun 29 '12 at 17:29
    
Unless you can update your app to use relative uri paths everywhere or live under /dev/ on the backend, you probably will need to use a second server. The rewrite you're doing now is doing the same thing as the trailing / you originally had on the proxy_pass –  kolbyjack Jun 29 '12 at 18:06
    
You mean second physical server, or second server block? Thanks –  Daniel Huger Jun 29 '12 at 18:14
    
Second server block. server { server_name dev.domain.com; ... } –  kolbyjack Jun 29 '12 at 18:20

Update: My answer is wrong. But, I'm leaving it here so that whoever sees this wouldn't make my mistake!

location / block should probably be the last block of any server. In your configuration, it comes first. That's probably the reason for the issue you described. So, please try the following...

server {
        server_name localhost 127.0.0.1;
        server_name_in_redirect off;

        location /dev {
                proxy_pass http://10.10.0.59/;
                    .........
        }

        location / {
                proxy_pass http://10.10.0.56/;
                     ........
share|improve this answer
    
The order of static location blocks does not matter. See wiki.nginx.org/r/location –  kolbyjack Jun 27 '12 at 12:11
    
@kolbyjack You're right. I just tested it myself on a demo setup. Thanks for sharing the right information. –  Pothi Jun 27 '12 at 12:37
    
@PothiKalimuthu Thanks for helping anyway :) –  Daniel Huger Jun 29 '12 at 17:29

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.