A
A
Alexander2018-07-20 11:19:25
Nginx
Alexander, 2018-07-20 11:19:25

NGINX Automatic creation of subdomains?

Trying to migrate to NGINX. I need all folders created in the root of the domain to be subdomains, except for the main /htdocs of course...
The directory structure is:
/var/www/ustim.ru/htdocs
/var/www/ustim.ru/forum
Basically domain, we go to the htdocs directory. All subdomains are in the ustim.ru folder, one is already there /forum
There is still a simple domain config

spoiler
server {
        listen 80 default;
        server_name ustim.ru;

        root /var/www/ustim.ru/htdocs;
        include /etc/nginx/templates/php-fpm.conf;
        index index.html index.htm index.php;

        access_log /var/log/nginx/ustim.ru_access.log;
        error_log /var/log/nginx/ustim.ru_error.log;
}

Can you tell me a working version of the configuration with subdomains?
On Apache everything worked with this config
spoiler
NameVirtualHost *:80

<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName ustim.ru
        ServerAlias www.ustim.ru
        DocumentRoot /var/www/ustim.ru/htdocs

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName ustim.ru
        ServerAlias *.ustim.ru
        UseCanonicalName Off
        VirtualDocumentRoot /var/www/ustim.ru/%-3

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
unwrecker, 2018-07-20
@unwrecker

I will advise my own article on Habré :)
https://habr.com/post/142648/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question