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 am trying to separate our application server from our website gallery storage. I have an application server on xxx.xxx.xxx.1 and gallery server with all the images on xxx.xxx.xxx.2 . Now I want to make it so every time request comes into server with the ending of *.jpeg and/or beginning of www.domain.com/uploads, would get redirected to www.gallerydomain.com.

I have checked a second server and it is working perfectly fine.

Now the on the 1st server i tried doing :

location /uploads {
        proxy_pass      http://www.gallerydomain.com;
}

but it doesn't seem to work.

Any1 has any experience with this kind of situation in Nginx ? Or could some1 point me to the right direction ? Much appreciated.

share|improve this question
    
Do you want to redirect the client, or do you want to transparently proxy their request? –  Shane Madden Mar 8 '12 at 4:58
    
I want to redirect a client. Well the idea is that while client is browsing, the picture requests comes from different domain. Also id user is uploading pictures it uploads it to that domain. –  Katafalkas Mar 8 '12 at 8:33
    
Is it basis of a load balancing I an talking about ? –  Katafalkas Mar 8 '12 at 8:36

2 Answers 2

Sorry, I did not see your comment above. To make redirections on client-side this can be useful :

server {

    server_name    domain.com;

    ...

    rewrite ^/uploads/(.*)$      http://www.gallerydomain.com/$1        permanent;
    rewrite ^/(.*)\.jpg$         http://www.gallerydomain.com/$1.jpg    permanent;

    ...

}

Nginx returns an 'HTTP 301 Moved permanently' response on every request that matches a rewrite pattern. This way the browser redirects to the new location (and is aware of), according to the content of the 'Location:' HTTP response header.

share|improve this answer
    
Cheers, I will test it out maybe this weekend, will give you heads up when I get results –  Katafalkas Mar 9 '12 at 14:06

You can resolve this by using a regular expression in the location block :

location ~ ^/uploads/|\.jpg$ {
    proxy_pass http://www.gallerydomain.com;
}
share|improve this answer

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.