There is a constant redirection of all subdomains to the main site. You must exclude the files subdomain from this permanent redirect.
I read an article on StackOverflow , but did not understand anything.
Ideally, it should work like this:
- https://domain.ru -> https://domain.ru
- https: //*.domain.ru -> https://domain.ru
- https://files.domain.ru -> https://files.domain.ru
Primary domain file with redirection:
server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name domain.ru; root /var/www/sites/domain.ru/; ssl_certificate /etc/letsencrypt/domain.ru/fullchain.cer; ssl_certificate_key /etc/letsencrypt/domain.ru/domain.ru.key; include /etc/nginx/snippets/ssl-params.conf; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name *.domain.ru; # SSL ssl_certificate /etc/letsencrypt/domain.ru/fullchain.cer; ssl_certificate_key /etc/letsencrypt/domain.ru/domain.ru.key; return 301 https://domain$request_uri; } File with selected subdomain:
server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name domain.ru; root /var/www/sites/__subdomain/domain.ru/; ssl_certificate /etc/letsencrypt/domain.ru/fullchain.cer; ssl_certificate_key /etc/letsencrypt/domain.ru/domain.ru.key; include /etc/nginx/snippets/ssl-params.conf; } server { listen 80; listen [::]:80; server_name files.domain.ru; return 301 https://files.domain.ru$request_uri; } Changed the order of loading configs.
And since the redirect is permanent, not temporary, the browser will remember this and will not soon forget and will redirect to a shit out of ears despite the updated config on the web server. Cache will have to be cleaned.