0

I have a multisite installation that seems to be working just fine for the first site, but for the second site, the admin panel results in a "too many redirects" loop. What is the correct nginx or wordpress configuration to get this to work?

I have a non-WordPress installation at example.com
My first blog is setup at example.com/blog
My second blog is setup to be example.com/blog/tr. The frontend renders just fine.

The admin for the first site works just fine, as does the network admin panel. So https://example.com/blog/wp-admin and https://example.com/blog/wp-admin/network/ result in pages that work fine. The url https://example.com/blog/tr/wp-admin results in too many redirects, though.

My nginx configuration for the wp-admin sections looks like this

if (!-e $request_filename) {
     rewrite /wp-admin$ $scheme://$host$uri/ permanent;     
     rewrite /wp-admin$ $host/$uri/ permanent;
     rewrite ^(/[^/]+)?(/wp-.*) $2 last;
     rewrite ^(/[^/]+)?(/.*.php) $2 last;
}

Here are my wp_blogs and wp_site tables

mysql> SELECT * FROM wp_site;
+----+-------------+--------+
| id | domain      | path   |
+----+-------------+--------+
|  1 | example.com | /blog/ |
+----+-------------+--------+

mysql> SELECT blog_id, site_id, domain, path FROM wp_blogs;
+---------+---------+-------------+-----------+
| blog_id | site_id | domain      | path      |
+---------+---------+-------------+-----------+
|       1 |       1 | example.com | /blog/    |
|       2 |       1 | example.com | /blog/tr/ |
+---------+---------+-------------+-----------+

wp-config.php

define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
define( 'DOMAIN_CURRENT_SITE', 'example.com' );
define( 'PATH_CURRENT_SITE', '/blog/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

I've tried changing the path for the second blog, to something with a different path like /blg/tr in case it was a path collision error, and I was still getting the problem. I also tried creating a second site in wp_sites and associating the second blog with that second site, also didn't do anything different.

I also put in specific nginx location blocks for specifically /blog/tr/wp-admin and that seemed to break it more in different ways.

Is there anything I am missing or additional documentation that I am not finding to help debug my second site's wp-admin section?

Reviewed documentation / suggested steps:
https://wordpress.org/support/article/debugging-a-wordpress-network/
https://www.wpbeginner.com/wp-tutorials/how-to-install-and-setup-wordpress-multisite-network
https://gist.github.com/JustThomas/141ebe0764d43188d4f2
Trying to access second site dashboard on a multisite configuration proceeds to an error
https://docs.bitnami.com/aws/how-to/troubleshoot-wordpress-issues/

EDIT: Full nginx config

server {
        listen 80;
        listen 443 ssl;
        ## Your website name goes here.
        server_name example.com;
        ## Your only path reference.
        root /Users/lfarr/Sites/blog;
        ## This should be in your http block and if it is, it's not needed here.
        index index.php;

        ssl_certificate     /usr/local/etc/nginx/ssl/example.com+4.pem;
        ssl_certificate_key /usr/local/etc/nginx/ssl/example.com+4-key.pem;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

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

        if (!-e $request_filename) {
            rewrite /wp-admin$ $scheme://$host$uri/ permanent;
            rewrite /wp-admin$ $host/$uri/ permanent;
            rewrite ^(/[^/]+)?(/wp-.*) $2 last;
            rewrite ^(/[^/]+)?(/.*.php) $2 last;
        }

        #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;
        }

        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi_params;
                fastcgi_intercept_errors on;
                fastcgi_pass fastcgi_backend;
                #The following parameter can be also included in fastcgi_params file
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
}
2

1 Answer 1

0

There seems to be some issue the the nginx config. Is there any reason you have modified this rule differently then as documented in the wordpress documentation ? (https://wordpress.org/support/article/nginx/#wordpress-multisite-subdirectory-rules)

I am specifically talking about following rule :

if (!-e $request_filename) {
 rewrite /wp-admin$ $scheme://$host$uri/ permanent;     
 rewrite /wp-admin$ $host/$uri/ permanent;
 rewrite ^(/[^/]+)?(/wp-.*) $2 last;
 rewrite ^(/[^/]+)?(/.*.php) $2 last; 
}

I think you can remove the 3rd line in the above rule ( rewrite /wp-admin$ $host/$uri/ permanent; ) as it's not there in the documentation too .. and I think all needed is already there in the first rule of this block.

Beside that in the last rule (rewrite ^(/[^/]+)?(/.*.php) $2 last;) is missing an escape sequence, which is also present in the documentation. So Can you try replacing the above block completely as present in the document like shown below ?

if (!-e $request_filename) {
        rewrite /wp-admin$ $scheme://$host$request_uri/ permanent;
        rewrite ^(/[^/]+)?(/wp-.*) $2 last;
        rewrite ^(/[^/]+)?(/.*\.php) $2 last;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.