I am trying to setup WordPress Multisite with subdirectories behind nginx.
Initially my WordPress was hosted at https://example.com/wordpress
, and now I am moving it to Multisite.
wp-config.php
seems fine:
define('WP_DEBUG', false);
define( 'WP_ALLOW_MULTISITE', true );
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'example.com');
define('PATH_CURRENT_SITE', '/wordpress/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1); `
My nginx.conf
is:
server {
listen 80;
server_name example.com;
root /var/www/; # wordpress is at /var/www/wordpress, All wp files are in this wordpress folder
index index.php;
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
recursive_error_pages on;
location / {
try_files $uri $uri/ /wordpress/index.php?q=$uri&$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Pass uploaded files to wp-includes/ms-files.php.
rewrite /files/$ /wordpress/index.php last;
if ($uri !~ wp-content/plugins) {
rewrite /files/(.+)$ /wordpress/wp-includes/ms-files.php?file=$1 last;
}
# Rewrite multisite '.../wp-.*' and '.../*.php'.
if (!-e $request_filename) {
rewrite_log on;
rewrite ^/(/[^/]+)?(/wp-.*) wordpress/$2 last;
rewrite ^/(/[^/]+)?(/.*\.php) wordpress/$2 last;
# rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
# rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location ~ \.php$ {
set $skip_cache 0;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $skip_cache 1;
}
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache microcache;
fastcgi_cache_valid 200 5m;
}
}
I create a website now called "Site2": https://example.com/wordpress/site2
But the this site does not load the page properly. When I view
https://example.com/wordpress/site2/wp-admin/
I get the error:
This webpage has a redirect loop.
An immediate help would be really appreciated.
ok, if you want your sites to run as
https://example.com/site1
https://example.com/site2
here is what you can do,
go to network setup>sites change the site2 address from /wordpress/site2 to /site2
Also you need to fix, nginx config as follows
# rewrite ^/(/[^/]+)?(/wp-.*) wordpress/$2 last;
# rewrite ^/(/[^/]+)?(/.*\.php) wordpress/$2 last;
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) /wordpress$1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ /wordpress$1 last;
That is you need to use your uncommented code, with some fix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With