T
T
thisall2020-11-06 14:44:47
Nginx
thisall, 2020-11-06 14:44:47

How to make dynamic subdomains?

How can I make it so that, for example, the user accesses the link 789789.76733056.example.com
And the server accesses one folder where the site will be located.

The root folder /var/www/platforms;

I did this, the server understands this link, but does not open the correct directory.

server {
    listen 80;
    server_name example.com *.example.com;
    root /var/www/platforms;

    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 question

Ask a Question

731 491 924 answers to any question