### Use case # example.com has a non-WordPress installation at its root # example.com/blogs is a WordPress multisite sub-directory installation # example.com/blogs/blog1 is a site in WP multisite # example.com/blogs/blog2 is another site in WP multisite # The site would be accessed primarily as example.com (instead of www.example.com) # Please replace blogs with the actual name of the sub-directory inwhich WP is (would be) installed ### Remember that IfIsEvil, if used inappropriately. # Ref: http://wiki.nginx.org/IfIsEvil # Redirect www.example.com/anything to example.com/anything server { listen 80; server_name www.example.com; return 301 $scheme://example.com$request_uri; } # Process requests to example.com server { listen 80; server_name example.com; index index.php; # Change this to the actual location of non-WordPress files root /home/username/sites/example.com/public; # Logs access_log /var/log/nginx/example.com-access.log combined buffer=64k flush=5m if=$loggable; error_log /var/log/nginx/example.com-error.log; ### modified version of globals/mu-files.conf; # For uploads if ( $uri ~ "files" ) { rewrite ^/blogs/(?:.*/)?files/(.+) /blogs/wp-includes/ms-files.php?file=$1; } ### modified version of globals/mu-dir.conf; # For sub-directory redirects # Only one would apply # If two needed to be applied, it'd throw a 404 if (!-e $request_filename) { rewrite ^/blogs/[_0-9a-zA-Z-]+(/wp-(content|admin|includes).*) /blogs$1 break; rewrite ^/blogs/[_0-9a-zA-Z-]+(/.*\.php)$ /blogs$1 break; } # Process PHP requests location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include "fastcgi.conf"; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; fastcgi_pass fpm; } # To process WordPress site/s location /blogs { try_files $uri $uri/ /blogs/index.php$is_args$args; } # Let's include usual location directives, including 'location / { try files ; }' directive # To process the non-WordPress PHP site include globals/assets.conf; include globals/restrictions.conf; # The rewrite magic location / { try_files $uri $uri/ /index.php$is_args$args; } }