Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 using nginx for request forwarding on my server.I have two server blocks,one for the main website and the other server block to serve my S3 static content.

   server {
      listen 80;

       access_log  off;
       error_log off;

      location / {
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        Host            $host;
        proxy_redirect          off;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout 90;
        proxy_send_timeout 90;
        proxy_read_timeout 90;
        client_max_body_size 10m;
        client_body_buffer_size 128k;
        proxy_buffer_size 4k;
        proxy_buffers 4 32k;
        proxy_busy_buffers_size 64k;

 # Server for S3  This accepts anything apart from the above two
server {
    # Listen on port 80 for all IPs associated with your machine
    listen 80 default_server;

    # Catch all other server names
    server_name _;

This works for but if I enter it fails i.e gives error This webpage has a redirect loop. I referred documetation and it says we can add multiple domains using space.

I have my DNS record for www @ and @ refers to the root ip address.

How can I get it working for both in the first server block and for any other domain in the second server block?

In my .htaccess file I have

 RewriteRule (.*)$1 [R=301,L]
 RewriteRule ^$1 [L]
 RewriteRule ^$1  index.php [L]
share|improve this question
nginx doesn't have any redirects defined. Check your application. – Michael Hampton Feb 26 '14 at 14:01
sorry sir,I did not get.Can you please elaborate a bit.Do you mean there is no issue in the config above? – KillABug Feb 26 '14 at 14:02

The culprit here is the first RewriteRule in your Apache configuration. It tells Apache to redirect every request to

So, when nginx sends a request to the request is routed to Apache, and the first RewriteRule redirects that request to, thus causing a redirect loop.

The best solution is to migrate the redirects to nginx, like xxdesmus suggested.

Another option is to restrict the first RewriteRule to be applied only when the HTTP Host header is with a RewriteCond directive.

share|improve this answer

Instead of handling your redirects in your Apache htaccess file, why not just handle those redirects directly in Nginx instead? Forward root -> www with a 301 redirect, and then in the www server_name block send that to your proxy_pass (Apache)?

share|improve this answer
I did not get you sir.I will explain my scenario.I use nginx as a proxy server and it proxies all requests to apache on the same machine.As apache is not powerful enough to handle it had to go with nginx.Nginx is basically to display static html pages in my s3 bucket – KillABug Feb 27 '14 at 11:26

Your Answer


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.