Answer the question
In order to leave comments, you need to log in
nginx. How to show an error when trying to access a non-existent subdomain?
There are 3 subdomains
test1.domain.ru
test2.domain.ru
test3.domain.ru
and the main domain domain.ru
Each has its own nginx config and everything works. However, if you go to some test234123.domain.ru, then the contents of domain.ru will appear. How to write an error in this case?
Answer the question
In order to leave comments, you need to log in
nginx first decides which server should process the request. Consider a simple configuration where all three virtual servers are listening on port *:80:https://nginx.org/ru/docs/http/request_processing.htmlserver { listen 80; server_name example.org www.example.org; ... } server { listen 80; server_name example.net www.example.net; ... } server { listen 80; server_name example.com www.example.com; ... }
In this configuration, nginx only checks the “Host” field of the request header to determine which server to send the request to. If its value does not match any of the server names, or the request header does not contain this field at all, nginx will forward the request to the default server for that port. In the configuration above, the default server will be the first server, which is the default behavior of nginx. The default server can be set explicitly using the default_server parameter in the listen directive:server { listen 80 default_server; server_name example.net www.example.net; ... }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question