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!
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.