Report this

What is the reason for this report?

nginx catch-all server_name for WordPress Multisite

Posted on April 15, 2016

Is it possible to do something like?

server_name   * ;

I don’t want to have to manually add each site like this:

server_name examplewp.com *.examplewp.com shoppingsite.com companysite.org;

As there may be hundreds of sites on a multisite.

This is my current code:

server {

  listen 80 ;

  server_name   mainsite.com  *.mainsite.com site1.co site2.co site3.co ;
  access_log   /srv/www/mainsite.com/logs/access.log;
  error_log    /srv/www/mainsite.com/logs/error.log;

  root  /srv/www/mainsite.com/current/web;
  index index.php index.htm index.html;

  charset utf-8;


  rewrite /wp-admin$ $scheme://$host$uri/ last;
  rewrite ^/(wp-.*.php)$ /wp/$1 last;
      rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;
  add_header X-Content-Type-Options "nosniff" always;
  add_header X-Frame-Options SAMEORIGIN;
  add_header X-Xss-Protection "1; mode=block" always;


  include includes.d/mainsite.com/*.conf;
  include wordpress.conf;

  location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    fastcgi_pass unix:/var/run/php5-fpm-wordpress.sock;
    }
}

"mainsite.com.conf" [readonly] 41L, 1301C

I tried this and it did’t work:

server {

  listen 80 default_server ;

  server_name   _ ;
  access_log   /srv/www/mainsite.com/logs/access.log;
  error_log    /srv/www/mainsite.com/logs/error.log;

  root  /srv/www/mainsite.com/current/web;
  index index.php index.htm index.html;

  charset utf-8;


  rewrite /wp-admin$ $scheme://$host$uri/ last;
  rewrite ^/(wp-.*.php)$ /wp/$1 last;
      rewrite ^/(wp-(content|admin|includes).*) /wp/$1 last;
  add_header X-Content-Type-Options "nosniff" always;
  add_header X-Frame-Options SAMEORIGIN;
  add_header X-Xss-Protection "1; mode=block" always;


  include includes.d/mainsite.com/*.conf;
  include wordpress.conf;

  location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    fastcgi_pass unix:/var/run/php5-fpm-wordpress.sock;
    }
}

"mainsite.com.conf" [readonly] 41L, 1301C

I’m a complete nginx noob and any help is much appreciated!!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This question was answered by @michaelharrigan:

Problem solved. There was another .conf file (no-default.conf) that also had default_server defined. Once I deleted no-default.conf the catch-all was working.

View the original comment

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.