Answer the question
In order to leave comments, you need to log in
Nginx autosubdomain and 403 error, what to do?
The server itself uses Nginx (although Apache2 is also installed). I'm trying to make autosubdomains on the site.
That is, when you navigate to subdomain.site.ru, it will open from /var/www/site.com/subdomain.
But if there is no such folder - then 404.
What script do I use for Nginx:
server {
listen 80;
server_name example.com *.example.com;
root /var/www/example.com/$subdomain;
set $subdomain "";
if ($host ~* ^([a-z0-9-\.]+)\.example.com$) {
set $subdomain $1;
}
if ($host ~* ^www.example.com$) {
set $subdomain "";
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question