Skip to content

Instantly share code, notes, and snippets.

@donaldallen
Last active December 17, 2015 00:38
Show Gist options
  • Save donaldallen/5522008 to your computer and use it in GitHub Desktop.
Save donaldallen/5522008 to your computer and use it in GitHub Desktop.
Wildcard subdomains.
server {
listen 80;
server_name ~^(?<subdomain>.+?)\.domain\.com$;
if (!-d /usr/share/nginx/$subdomain) {
return http://www.domain.com/;
}
root /usr/share/nginx/$subdomain;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SERVER_NAME $subdomain.domain.com;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment