Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Re: dynamic virtual host and sub domains

$
0
0
It looks like this might be working for me.

http {

server {
listen 80;
index index.html index.htm index.php;
set $basepath "/var/www/vhosts";
server_name ~^(?<sub>.+?)\.(?<domain>.+)$;

set $root $basepath/$domain/htdocs/www;

# if the domain is missing a subdomain then the default path will fail
if ( !-d $basepath/$domain/htdocs/www ){
rewrite ^ $scheme://www.$host$uri redirect;
}

set $root $basepath/$domain/htdocs/$sub;

# sub domain path doesn't exist redirec to default
if ( !-d $root ){
rewrite ^ $scheme://www.$domain$uri redirect;
}


location / {
root $root;
}

location ~ \.php$ {
root $root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}

}
}

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>