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 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 and rest of the request to be redirected to Eg:If a user request,it should go to,and rest of the requests should go to

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

# Catch only requests for

location / {
    # Pass the request to your Apache server running on IP x.x.x.x and port 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 site the request is rewritten to 
    # / 
    rewrite ^(.*)$ /$host_without_www$1 break;

    # The rewritten request is passed to S3

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
RequestId: 62258F8B3F01AB4C
HostId: f0hxEF/kGTwfwu4uoZ3JxXpdak+vNtLQU9+mfcyg3m8ybIsty9GzbSLnU01jdvVX

Eg: I have a bucket name)/ name).Now I want it to match the folder name but it looks for the bucket with the name
If I pass it to any other domain say 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


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

Browse other questions tagged or ask your own question.