Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to proxy several sites using nginx, and by the nature of the source I'm interested, they happen to have similar path, say /common/path. How can I get them served in different paths in my site? Say a.com/common/path goes to mysite/a-proxy/; b.com/common/path goes to mysite/b-proxy/?

I would imagine it has something to do with combination with alias and proxy_pass but not exactly sure how to deal with this. Any hint? At the bottom is my current conf file, note that a and b on the original server should have different path so that they can both be proxied in my site.

I've tried to setup sub-domain so that I can direct each of them to different server, but it seems like an overkill?

upstream a_upstream {
    server a.com;
}

upstream b_upstream {
    server b.com;
}

server {
    listen 80;
    server_name mysite.com;
    root /home/me/public_html/mysite;
    index index.html index.htm;

    location /common/path1 {
        proxy_pass http://a_upstream;
    }

    location /common/path2 {
        proxy_pass http://b_upstream;
    }    
}
share|improve this question
    
Your written question and code seems to be at a conflict. Are you saying that the user goes to the address: "a.com/common/path" which is then pulled from "mysite.com/a-proxy/" or are you saying a user goes to "mysite.com/a-proxy/" which then pulled from a.com? Also, setting up multiple server { ... } is the recommended way to setup virtual hosts. – Grumpy Jan 11 '13 at 6:34
    
My script is not able to achieve what I want to do right now, just a reference for current setting. As you said, one solution is to set up multiple server {...} but I guess it involves subdomain setup or so on, so wondering if there is easier way to do so. – clwen Jan 11 '13 at 14:23
1  
I still feel that there's a gap in your question. I don't really understand what you're trying to achieve. Try editing your question to add further details or a step by step of what you expect to happen starting from user and all the way to the backend. – Grumpy Jan 11 '13 at 16:15

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.