# HG changeset patch # User Ruslan Ermilov # Date 1318239400 0 # Node ID 6327603448e2c46c5a1bbe2b2f24d21e3798ceb6 # Parent 0987079ad08f9cc3cb82a84a5521eab777d0aaba Updated the "How to prevent processing requests with undefined server names" example to use the "server_name" directive with an empty string argument to match requests without the "Host:" request header line. diff -r 0987079ad08f -r 6327603448e2 xml/en/docs/http/request_processing.xml --- a/xml/en/docs/http/request_processing.xml Mon Oct 10 09:23:09 2011 +0000 +++ b/xml/en/docs/http/request_processing.xml Mon Oct 10 09:36:40 2011 +0000 @@ -73,22 +73,43 @@ title="How to prevent processing requests with undefined server names"> -If you do not want to process requests with undefined “Host” -header lines, you may define a default server that just drops the requests: +If you do not want to process requests without the
Host
+header line, you may define a server that just drops the requests: server { - listen 80 default_server; + listen 80; + server_name ""; + return 444; +} + + +Here, the server name is set to an empty string which will match +requests without the
Host
header line, +and a special nginx’s non-standard code 444 +is returned that closes the connection. +Since version 0.8.48, this is the default setting for the +server name, so the server_name "" can be omitted. +In earlier versions, the machine's hostname was used as +a default server name. + + +Versions prior to 0.7.11 did not support an empty server name, +so another configuration was needed to achieve the same effect: + + +server { + listen 80 default; server_name _; return 444; } -We have chosen the non-existent domain name “_” -as the server name and returned nginx’s special non-standard -code 444 that closes the connection. -Note that you should set a name for this server, -otherwise nginx will use the hostname. +A non-existent domain name “_” is used as the server name, the server +should be the first or marked as default. +Note that the server name must be set explicitly here, otherwise nginx +will use the hostname. +