S
S
Sergey2015-01-27 22:50:06
Nginx
Sergey, 2015-01-27 22:50:06

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 "";
    }
}

But as soon as I upload it to the server and open the site, I get a 403 Forbidden error in the forehead.
How to fix? Help..(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-01-27
@semihal

Can be closed, problem solved.

server { 
server_name site.com;
... конфиг для него ... ;
} 
server {
server_name ~^(?<subdomain>[a-z0-9\-]+)\.site\.com;
root /blah/bla/$subdomain;
... остальной конфиг; 
}

author: Vlad Zhivotnev toster.ru/answer?answer_id=351371

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question