Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Wordpress Multi Site Nginx configuration template for Nginx - based on Sam Smith's configuration at
server {
# ngx_pagespeed & ngx_pagespeed handler
include /usr/local/nginx/conf/pagespeed.conf;
include /usr/local/nginx/conf/pagespeedhandler.conf;
include /usr/local/nginx/conf/pagespeedstatslog.conf;
access_log /home/nginx/domains/ combined buffer=32k;
error_log /home/nginx/domains/;
root /home/nginx/domains/;
location / {
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
if (!-f $request_filename){
rewrite (.*) /index.php;
# Pass uploaded files to wp-includes/ms-files.php.
rewrite /files/$ /index.php last;
if ($uri !~ wp-content/plugins) {
rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
# Rewrite multisite '.../wp-.' and '.../.php'.
if (!-e $request_filename) {
rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
rewrite ^/[_0-9a-zA-Z-]+.(/wp-admin/.\.php)$ $1 last;
rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
include /usr/local/nginx/conf/wpsecure.conf;
include /usr/local/nginx/conf/wpnocache.conf;
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
/usr/local/nginx/conf/wpsecure.conf contents
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
# Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_
return 444;
location ~* \.(pl|cgi|py|sh|lua)\$ {
return 444;
location ~* (roundcube|webdav|smtp|http\:|soap|w00tw00t) {
return 444;
location ~ /(\.|wp-config.php|readme.html|license.txt) { deny all; }
/usr/local/nginx/conf/wpnocache.conf contents
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

This comment has been minimized.

Copy link

pchoanganh commented Jun 9, 2017

Help me with:

nginx configuration

charset utf-8;
error_page 404 /index.php;
location /CMS/ {
if (!-e $request_filename){
rewrite ^/CMS/site-([a-zA-Z0-9])$ /CMS/index.php/?__cms_subsite=$1 break;
if (!-e $request_filename){
rewrite ^/CMS/(.
)$ /CMS/index.php/$1 break;
if ($http_host ~* "^www.(.+)$"){
rewrite ^/CMS/(.)$ http://%1$request_uri redirect;
if ($script_filename ~ "-d"){
return 403;
if ($script_filename ~ "-f"){
return 403;
location /CMS/site {
rewrite ^/CMS/site-([a-zA-Z0-9]
)/(.*)$ /CMS/index.php/$2?__cms_subsite=$1 break;


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.