WordPress Multisite with Nginx

WordPress multisite with Nginx

If you are setting up a WordPress multisite, you might notice that the WordPress install displays the Apache settings for the .htaccess file, but does not provide any settings for Nginx.

How to setup WordPress Multisite

Open the wp-config.php file and add the following line

/* Multisite */
define('WP_ALLOW_MULTISITE', true);

Select the type of Multisite install you wish to use and click on the install button.

You will now see a config that would need to be added to your wp-config.php file. Once that is added and the file is saved, the multisite should be activated.

To activate multisite completely while using Nginx you would need to update the Nginx config as mentioned below.

Nginx config for Sub-directories for domain named example.com:

server {
        ##DM - uncomment following line for domain mapping	
        #listen 80 default_server;
	server_name example.com *.example.com ;
	##DM - uncomment following line for domain mapping
	#server_name_in_redirect off;

	access_log   /var/log/nginx/example.com.access.log;
	error_log    /var/log/nginx/example.com.error.log;

	root /var/www/example.com/htdocs;
	index index.php;

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

	location / {
		try_files $uri $uri/ /index.php?$args ;
	}

	location ~ .php$ {
		try_files $uri =404;
		include fastcgi_params;
		fastcgi_pass 127.0.0.1:9000;
	}

	location ~* ^.+.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|
        tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
		access_log off;	log_not_found off; expires max;
	}

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

Nginx Config for Sub-domains for domain named example.com :

server {
        ##DM - uncomment following line for domain mapping	
        #listen 80 default_server;
	server_name example.com *.example.com ;
	##DM - uncomment following line for domain mapping
	#server_name_in_redirect off;

	access_log   /var/log/nginx/example.com.access.log;
	error_log    /var/log/nginx/example.com.error.log;

	root /var/www/example.com/htdocs;
	index index.php;

	location / {
		try_files $uri $uri/ /index.php?$args ;
	}

	location ~ .php$ {
		try_files $uri =404;
		include fastcgi_params;
		fastcgi_pass 127.0.0.1:9000;
	}

	location ~* ^.+.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|
        tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
		access_log off;	log_not_found off; expires max;
	}

	location = /robots.txt { access_log off; log_not_found off; }
	location ~ /. { deny  all; access_log off; log_not_found off; }
}
© 2024 WPOven Inc. All rights reserved. WPOven® and WordPress® are registered trademarks.
WPOven is the best Managed WordPress hosting for agencies and businesses that want to succeed. With Unlimited sites hosting option, its easy to use and manage, so you can focus on growing your business. 
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram