Hello,
copying my post in russian here as well.
I spend a lot of time trying to configure following scenario -
*.domain.com should take files from /srv/www/vhosts/domain.com/*/
also PHP files should be handled by apache with same scenario.
So currently it works super fine on pure apache with following rewrite rule
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com
RewriteCond /srv/www/vhosts/domain\.com/%1 -d
RewriteRule ^(.*) /%1/$1 [L]
and I wish to install nginx as frontend (it should server static, not just proxy)
I found 2 options
1)
server {
listen 80;
server_name ~^(.*)\.nginxdomain\.com$;
#if directory doesn't exist
if (!-d /home/domains/nginxdomain.com/public/$1) {
rewrite . http://www.nginxdomain.com/ redirect;
}
# Sets the correct root
root /home/domains/nginxdomain.com/public/$1;
it doesnt work, when for example I request picture.jpg Nginx searhes for file under ../domain/jpg/.. (jpg instead of subdomain)
or if picture.png it would got to ../domain/png/..
2)
if ($host !~* ^www\.domain\.tld$) {}
if ($host ~* ^([^.]+)\.domain\.tld$) {
set $auto_subdomain $1;
}
if (-d /var/www/domain.tld/www/$auto_subdomain) {}
if (-f /var/www/domain.tld/www/$auto_subdomain$uri) {
rewrite ^(.*)$ /$auto_subdomain$uri;
break;
}
I dont really understand this, but it doesnt work like that.
I would appreciate any help,
thanks,
Igor S.