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:

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.

  • one
    Just identify the server block with the same name listening to port 443 as the other blocks - Alexey Ten
  • @Alexey Ten, it is already defined in the file with the selected subdomain. - Konstantin Sobolev
  • There is only port 80 - Alexey Ten
  • @AlexeyTen, point an example. I do not understand what you mean. - Konstantin Sobolev
  • Hmm, do you understand how http works in general and what, in particular, does nginx mean the listen directive? - Alexey Ten

0