Mercurial > hg > nginx-site
comparison xml/en/docs/http/request_processing.xml @ 73:6327603448e2
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.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Mon, 10 Oct 2011 09:36:40 +0000 |
parents | 9d544687d02c |
children | e9948ec6286b |
comparison
equal
deleted
inserted
replaced
72:0987079ad08f | 73:6327603448e2 |
---|---|
71 | 71 |
72 <section name="how_to_prevent_undefined_server_names" | 72 <section name="how_to_prevent_undefined_server_names" |
73 title="How to prevent processing requests with undefined server names"> | 73 title="How to prevent processing requests with undefined server names"> |
74 | 74 |
75 <para> | 75 <para> |
76 If you do not want to process requests with undefined “Host” | 76 If you do not want to process requests without the <header>Host</header> |
77 header lines, you may define a default server that just drops the requests: | 77 header line, you may define a server that just drops the requests: |
78 | 78 |
79 <programlisting> | 79 <programlisting> |
80 server { | 80 server { |
81 listen 80 default_server; | 81 listen 80; |
82 server_name ""; | |
83 return 444; | |
84 } | |
85 </programlisting> | |
86 | |
87 Here, the server name is set to an empty string which will match | |
88 requests without the <header>Host</header> header line, | |
89 and a special nginx’s non-standard code 444 | |
90 is returned that closes the connection. | |
91 Since version 0.8.48, this is the default setting for the | |
92 server name, so the <code>server_name ""</code> can be omitted. | |
93 In earlier versions, the machine's <i>hostname</i> was used as | |
94 a default server name. | |
95 | |
96 <note> | |
97 Versions prior to 0.7.11 did not support an empty server name, | |
98 so another configuration was needed to achieve the same effect: | |
99 | |
100 <programlisting> | |
101 server { | |
102 listen 80 default; | |
82 server_name _; | 103 server_name _; |
83 return 444; | 104 return 444; |
84 } | 105 } |
85 </programlisting> | 106 </programlisting> |
86 | 107 |
87 We have chosen the non-existent domain name “_” | 108 A non-existent domain name “_” is used as the server name, the server |
88 as the server name and returned nginx’s special non-standard | 109 should be the first or marked as <code>default</code>. |
89 code 444 that closes the connection. | 110 Note that the server name must be set explicitly here, otherwise nginx |
90 Note that you should set a name for this server, | 111 will use the <i>hostname</i>. |
91 otherwise nginx will use the <i>hostname</i>. | 112 </note> |
92 </para> | 113 </para> |
93 | 114 |
94 </section> | 115 </section> |
95 | 116 |
96 | 117 |