Too many redirects using Nginx as reverse proxy

Hi rtCamp

I've followed your tutorial posted on:

I'm using Nginx as a reverse proxy to Apache. Using a slightly modified version of your config posted on above mentioned link, shown below, I'm getting error 310 - too many redirects. As far as I understand this is because the request is sent back and forth between Nginx and Apache.

I would REALLY appreciate if you could help me with this problem, since I've spent countless hours trying to configure this.

For caching I'm using WP Super Cache. For that reason and for simplicity I've removed the W3TC part, ending up with

map $http_host $blogid {

default -999;

#Must Read - 1; 2;  


server {

listen 80;

    server_name *;          
    server_name *;  

    server_name_in_redirect off;  

    access_log /home/www/;  
    error_log /home/www/ debug;  

    root /home/www/;   
    index index.php index.html index.htm;  

    set $cache_uri $request_uri;  

    # POST requests and urls with a query string should always go to PHP  
    if ($request_method = POST) {  
            set $cache_uri 'null cache';  
    if ($query_string != "") {  
            set $cache_uri 'null cache';  

    # Don't cache uris containing the following segments  
    if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {  
            set $cache_uri 'null cache';  

    # Don't use the cache for logged in users or recent commenters  
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") {  
            set $cache_uri 'null cache';  

    # Use cached or actual file if they exists, otherwise pass request to WordPress  
    location / {  
            #try_files /wp-content/w3tc-$host/pgcache/$cache_uri/_index.html $uri $uri/ /index.php?$args;  
            try_files $uri $uri/ /index.php?$args;  

    location ~ \.php$ {  
            try_files $uri /index.php;  
            proxy_pass; # set to your own port                                                                                                                     
            proxy_redirect off;  
            proxy_set_header Host $host;  
            proxy_set_header X-Real-IP $remote_addr;  
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  

            client_max_body_size 10m;  
            client_body_buffer_size 128k;  

            proxy_connect_timeout 90;  
            proxy_send_timeout 90;  
            proxy_read_timeout 90;  
            proxy_buffer_size 4k;  
            proxy_buffers 4 32k;  
            proxy_busy_buffers_size 64k;  
            proxy_temp_file_write_size 64k;  

    #WPMU Files  
    if ($request_uri ~* "\/files\/(.*)"){  
            set $rtfile $1;  

    location ^~ /files {  
            try_files /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$rtfile ;  
            access_log off; log_not_found off;      expires max;  

    #WPMU x-sendfile to avoid php readfile()  
    location ^~ /blogs.dir {  
            alias /home/www/;  
            access_log off; log_not_found off;      expires max;  



You don’t need any caching related code in Nginx in your case. You can remove all checks above location / { } block as WordPress will use Apache .htaccess rewrite rules in your case.

But I strongly recommend removing Apache because you can handle everything using Nginx and it will be much faster.