Update: This article is updated for WordPress 3.5 multisite’s file-handling.
In this article, we will setup WordPress Multisite using Subdomains. If you haven’t created a WordPress Multisite network, please check this guide first.
Nginx Config
Below is recommended Nginx configuration.
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 /index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
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; }
}
Domain Mapping
You need to uncomment few lines in above nginx-config to get domain-mapping working. Apart from above config changes, you can read this guide to setup/configure domain-mapping.
Must Read:
- Checklist For Perfect WordPress-Nginx Setup - It will help you verify if your caching will work after PHP/MySQL crash.
- Nginx Maps for Better Static File Handling in WordPress-Multisite - useful for multisite created before WordPress 3.5 released
- WordPress-Nginx tutorials

where are these changes made to the nginx.conf file??
While you can add above lines in nginx.conf, for ease-of-maintenance we follow certain conventions as outlined in this article – http://rtcamp.com/tutorials/conventions-file-system-layout-for-ideal-wordpress-nginx-setup/
hi, in which cases is blogs.dir used? i’ve just configured a subdomains multisite with v3.5.1 and uploading an image on blogid=2 creates it under wp-content/uploads/sites/2/ so it’s served as a static file by nginx.
It looks like you have installed a fresh WordPress setup.
From WordPress 3.5,
blogs.dirfolder is no longer created. You can ignore everything related toblogs.dir. Above config will work without any issues.As there are many tutorials related to WordPress Multisite, I will update them in one go soon.
If you face any issue, please let me know.
I tried using this config but I kept getting a 502 error. I’m on WordPress 3.5.1. Is there something specific I need to change?
I actually figured it out thanks.
Glad to know that.
Sorry for delay in getting back to you.
Pardon the English because I’m from Brazil.
I have a WordPress with Nginx, put this configuration in nginx.conf, below the line that already existed. Nginx rebooted and still gives the error.
http://blog.codehost.com.br/
Remembering that this is a server with multiple domains.
Use with Centos WHM
Teste Nginx WordPress
Please paste error log or error message itself.
No error occurs, not only does the wildcard
If something is wrong, there must be error log.
Not sure how you are using Nginx with WHM but you can try this article to activate nginx debugging logs – http://rtcamp.com/tutorials/debugging-nginx-configuration/
First – I love your tutorials. They are the best at WordPress / Nginx and Multisite. I appreciate your logic and particularly liked your post showing us the best locations for certain files. I am moving from cpanel/whm to Nginx. The sites I have already moved are so much faster it is insane.
My question:
What is the best way to configure a second wordpress multisite on the same nginx configuration. I have configured exactly as you outlined for one – however – I know I run into issues whenever attempt to create another site-enabled config file… specifically in the lines here:
So when I go to create another multisite group, I do this again:
I have a great server I am using, and I have many small groups. I want to load multiple groups on once server. I have read a couple of places that you cannot put more than one multisite group on one nginx installation. I know that cannot be right.
Any suggestions or guidance would be greatly appreciated.
Thanks,
John
You can not have
listen 80 default_server;twice.If you are using multisite without domain mapping, then you can change
listen 80 default_server;to simplylisten 80;in one or both config.server_namefield alone is sufficient to map all subdomains for a particular domain correctly.If you are using domain-mapping on both sites then easiest you can do is to have 2 dedicated-IP’s on your server. For example, you get IP’s 1.1.1.1 and 2.2.2.2, then you can change
listen 80 default_server;tolisten 1.1.1.1:80 default_server;andlisten 2.2.2.2:80 default_server;in respective sites.If you do not have dedicated-IP’s then on smaller network, change
listen 80 default_server;to simplylisten 80;and then add all mapped-domains inserver_name. This is tedious but will work as long as number of mapped-domains are limited.