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 working on setting up a proxy server for my application.The use case is I want a specific set of requests to be redirect to say abc.com and rest of the request to be redirected to xyz.com. Eg:If a user request www.nginx.com,it should go to nginx.com:8000,and rest of the requests should go to sites.nginx.com

server {
# Listen on port 80 for all IPs associated with your machine
listen 80;

# Catch only requests for www.nginx.com
server_name www.nginx.com;

location / {
    # Pass the request to your Apache server running on IP x.x.x.x and port 8000
    proxy_pass http://www.nginx.com:8000;
}

} 

# Server for S3
server {
# Listen on port 80 for all IPs associated with your machine
listen 80;

# Catch all other server names
server_name _;

# This code gets the host without www. in front and places it inside 
# the $host_without_www variable

set $host_without_www $host;
if ($host ~* www\.(.*)) {
   set $host_without_www $1;
}

location / {
    # This code rewrites the original request, and adds the host without www in front
    # E.g. if someone requests 
    # /directory/file.ext?param=value 
    # from the coolsite.com site the request is rewritten to 
    # /coolsite.com/directory/file.ext?param=value 
    rewrite ^(.*)$ /$host_without_www$1 break;

    # The rewritten request is passed to S3
    proxy_pass http://sites.nginx.com;
 }
}

But currently I believe there is some issue with the second block.I have configured a domain to be proxied to a static website on S3(the rules are written accordingly). But instead of taking the folder name inside the bucket it searches for the bucket with the folder name and returns following error.

404 Not Found
Code: NoSuchBucket
Message: The specified bucket does not exist
BucketName: www.gobiggi.co.in
RequestId: 62258F8B3F01AB4C
HostId: f0hxEF/kGTwfwu4uoZ3JxXpdak+vNtLQU9+mfcyg3m8ybIsty9GzbSLnU01jdvVX

Eg: I have a bucket sites.nginx.com(bucket name)/www.abc.com(folder name).Now I want it to match the folder name but it looks for the bucket with the name www.abc.com
If I pass it to any other domain say www.xyz.com instead of the bucket,it works.

I need help in configuring this in the right way. Thank you for your time.

share|improve this question

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.