Answer the question
In order to leave comments, you need to log in
Nginx, how to disable invalid subdomains?
Recently, entries began to appear in the logs:
[Django] ERROR (EXTERNAL IP): Invalid HTTP_HOST header: '_tcp.domain.name. The domain name provided is not valid according to RFC 1034/1035
It was decided to cut such invalid domains on nginx. Google found the following regex for validation: https://stackoverflow.com/a/7933253/13084502
In the nginx config I wrote:
map $host $host_valid {
"~^(?!.{256})(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+(?:[a-z]{1,63}|xn--[a-z0-9]{1,59})$" 1;
default 0;
}
server {
listen 443 ssl;
server_name ~^(\w+)\.domain.name$;
if ($host_valid = 0) {
return 444;
}
...
}
Answer the question
In order to leave comments, you need to log in
You don't need to cut anything on purpose, it's enough to configure default_server with a twist, which will not skip requests for hosts not listed in the settings.
upd. read your comment above - but it doesn't change anything. Add server_name
with a wildcard that will process any of your subdomains, and the rest will fight back.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question