One nginx rules for lots of subdomain
- by komase
I have lots of subdomain in a server. Every subdomain has its own Drupal boost rules, like in below codes:
server {
server_name subdomain1.website.com;
location / {
root /var/www/html/subdomain/subdomain1.website.com;
index index.php;
set $boost "";
set $boost_query "_";
if ( $request_method = GET ) {
set $boost G;
}
if ($http_cookie !~ "DRUPAL_UID") {
set $boost "${boost}D";
}
if ($query_string = "") {
set $boost "${boost}Q";
}
if ( -f $document_root/cache/normal/$host$request_uri$boost_query.html ) {
set $boost "${boost}F";
}
if ($boost = GDQF){
rewrite ^.*$ /cache/normal/$host/$request_uri$boost_query.html break;
}
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/subdomain/subdomain1.website.com$fastcgi_script_name;
include fastcgi_params;
}
}
I adding all subdomain rules manually from time to time. The size of ngin.conf has become too big.
So,
I need one nginx rules which do:
subdomain1.website.com pointing to /var/www/html/subdomain/subdomain1.website.com
subdomain2.website.com pointing to /var/www/html/subdomain/subdomain2.website.com
subdomain3.website.com pointing to /var/www/html/subdomain/subdomain3.website.com
...and so on
(So that no more adding rules for subdomain .website.com I need in the future.)