Quantcast
Viewing all articles
Browse latest Browse all 31582

madra on "Nginx php-fpm multisite "too many redirects""

OK. I'm almost ready to throw the towel in on this one, so I'm hoping some of you clever folks out there can help me.

I've got a wordPress multisite setup running on Nginx... or I should say 'HAD' a WordPress multisite setup running on Nginx. At some stage last weekend, I suddenly found myself unable to login to the default domain –let's call it mydomain.com. I get the dreaded "The webpage at mydomain.com has resulted in too many redirects" error [insert equivalent wording for your browser of choice]. I am still able to login to both the other sites I have running on the setup; site1.mydomain.com and site2.mydomain.com, however that's not much good to me as obviously all the network settings, controls, etc. are under the default mydomain.com login.

I'm not sure exactly when the problem arose. I've been working on theming one of the subdomains and hadn't logged into the default domain for a few days, but everything was working fine up until a week or so ago. Since then, I've updated WordPress to the current version [3,5,2] and also updated a couple of plugins, as and when they required it. I've also 'slimmed down a few config files, after reading various articles but this mostly involved removing old commented out code, extracting certain sections into external files and swapping php-cgi for php-fpm, as my PHP backend. Chances are that somewhere in that morass of small insignificant changes, I've done *something* which has broken multisite, but I'm sure I've tried practically every suggestion I've found online, when duckduckgoing this problem, but nothing seems to work. Diagnosis isn't helped by the fact that neither Nginx, php-fpm or WordPress [with debug set to 'true'] are logging anything untoward. As far as they're concerned everything is hunky-dory, yet still I can't load my default domain, thanks to these 'redirect loop' errors.

anyway, enough waffling. Here are the relevant config file excerpts:

First off, my wp-congfig.php file:

<?php

define('DB_NAME', 'blah blah');

/* MySQL database username */
define('DB_USER', 'wordpress');

/* MySQL database password */
define('DB_PASSWORD', 'blah blah');

/* MySQL hostname */
define('DB_HOST', 'localhost:/var/run/mysqld/mysqld.sock');
define('DB_CHARSET', 'utf8');

/* Authentication Unique Keys and Salts. */

<REMOVED>

* WordPress Database Table prefix.
$table_prefix  = 'WP_';

/* WordPress Localized Language, defaults to English. */
define('WPLANG', 'en_IE');

/*For developers: WordPress debugging mode */
define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', false);
define('WP_DEBUG_LOG', true);

define( 'NOBLOGREDIRECT', 'http://mydomain.com' );

/* multisite */
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'mydomain.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

/** Cookies –commented out on orders of WPMU domain mapping plugin below **/
/* define('COOKIE_DOMAIN', 'mydomain.com'); */

/** WordPress MU Domain Mapping plugin **/
define( 'SUNRISE', 'on' );

/* That's all, stop editing! Happy blogging. */

/* Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');

/* Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

Next, the Nginx config file for the default domain:

map $http_host $blogid
{
        default 1;
        mydomain.com 1;
}

#       normalski
server
{
        listen   80 default_server;
        server_name  www.mydomain.com;
        rewrite ^/(.*) http://mydomain.com/$1 permanent;
        rewrite ^ http://mydomain.com$request_uri? permanent;
}

server
{
        listen 80;
        server_name mydomain.com;
        root /var/www/wordpress;
        access_log /var/log/mydomain.com-access.log;
        error_log /var/log/nginx/mydomain.com-error.log;
        include /etc/nginx/conf.d/W3TC.conf;
        include /etc/nginx/conf.d/restrictions.conf;
        include /etc/nginx/conf.d/wordpress-multisite.conf;
        include /etc/nginx/conf.d/php-fpm.conf;
}

#       SSL
server
{
        listen 443 ssl;
        server_name mydomain.com;
        ssl_certificate /etc/ssl/certs/mydomain.com.crt;
        ssl_certificate_key /etc/ssl/private/mydomain.com.key;
        root /var/www/wordpress;
        access_log /var/log/nginx/mydomain.com-access.log;
        error_log /var/log/nginx/mydomain.com-error.log;
        include /etc/nginx/conf.d/W3TC.conf;
        include /etc/nginx/conf.d/restrictions.conf;
        include /etc/nginx/conf.d/wordpress-multisite.conf;
        include /etc/nginx/conf.d/php-fpm.conf;
}

As you can see, the stripped down Nginx config file 'includes' several external config files. Here is the content of those, in the order they're included:

W3TC.conf:

#2013-07-07 Taken from: https://codex.wordpress.org/Nginx

# BEGIN W3TC CDN
location ~ \.(ttf|otf|eot|woff)$ {
   add_header Access-Control-Allow-Origin "*";
}
# END W3TC CDN

#W3 TOTAL CACHE CHECK
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';
}

restrictions.conf:

# Global restrictions configuration file.
# Designed to be included in any server {} block.</p>
location = /favicon.ico
{
        log_not_found off;
        access_log off;
}

location = /robots.txt
{
        allow all;
        log_not_found off;
        access_log off;
}

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /\.
{
 deny all;
}

# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$
{
 deny all;
}

wordpress-multisite.cong:

2013-070-07 Taken from: https://codex.wordpress.org/Nginx
#WordPress multisite subdirectory rules.
# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
        index index.php;
#       try_files $uri $uri/ /index.php?$args;
#       changed to this, coz of W3TC
        try_files /wp-content/w3tc-$host/pgcache/$cache_uri/_index.html $uri $uri/ /index.php?$args;
}

# Directives to send expires headers and turn off 404 error logging.
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 24h;
        log_not_found off;
}

location ~ ^/[_0-9a-zA-Z-]+/files/(.*)$ {
        try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ;
        access_log off; log_not_found off; expires max;
}

#avoid php readfile()
location ^~ /blogs.dir {
        internal;
        alias /var/www/example.com/htdocs/wp-content/blogs.dir ;
        access_log off; log_not_found off;      expires max;
}

# Uncomment one of the lines below for the appropriate caching plugin (if used).
#include global/wordpress-ms-subdir-wp-super-cache.conf;
include /etc/nginx/conf.d/W3TC.conf;

# Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
        rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
        rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}

php-fpm.conf:

#2013-07-16: Common php5-fpm PHP-handling config.
# php-fpm config file is at: /etc/php5/fpm/pool.d/www.conf

location ~ \.php
{
        # for security reasons the next line is highly encouraged
        try_files $uri =404;

        fastcgi_param  QUERY_STRING       $query_string;
        fastcgi_param  REQUEST_METHOD     $request_method;
        fastcgi_param  CONTENT_TYPE       $content_type;
        fastcgi_param  CONTENT_LENGTH     $content_length;

        fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME    $request_filename;

        fastcgi_param  REQUEST_URI        $request_uri;
        fastcgi_param  DOCUMENT_URI       $document_uri;
        fastcgi_param  DOCUMENT_ROOT      $document_root;
        fastcgi_param  SERVER_PROTOCOL    $server_protocol;

        fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
        fastcgi_param  SERVER_SOFTWARE    nginx;

        fastcgi_param  REMOTE_ADDR        $remote_addr;
        fastcgi_param  REMOTE_PORT        $remote_port;
        fastcgi_param  SERVER_ADDR        $server_addr;
        fastcgi_param  SERVER_PORT        $server_port;
        fastcgi_param  SERVER_NAME        $server_name;

        # If using a unix socket...
        # OSX version:
        #fastcgi_pass unix:/tmp/php-fpm.sock;
        # Debian version
        fastcgi_pass unix:/var/run/php5-fpm.sock;

}

So, there you have it. I'm sure i'm overlooking something so obvious it'll make me want to bequeath my brain to medical research for investigations into idiocy, but I've been staring at these damned config files for so long my head is swimming. Can someone put me out of my misery?

Thanks in advance!


Viewing all articles
Browse latest Browse all 31582

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>