Opened 10 years ago

Closed 10 years ago

#441 closed defect (invalid)

"Как предотвратить обработку запросов без имени сервера" - не работает

Reported by: openid.yandex.ru/Iremel36 Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.3.x
Keywords: return, server_name Cc:
uname -a: Linux web-test 3.0.13-0.27-default #1 SMP Wed Feb 15 13:33:49 UTC 2012 (d73692b) x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.4.1
built by gcc 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-pcre=../pcre-8.32 --with-zlib=../zlib-1.2.8 --with-http_gzip_static_module --with-http_stub_status_module --with-http_gunzip_module --without-http_autoindex_module --without-http_ssi_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_sub_module

Description

В документации http://nginx.org/ru/docs/http/request_processing.html есть:
===========
Если запросы без поля “Host” в заголовке не должны обрабатываться, можно определить сервер, который будет их отклонять:

server {
    listen      80;
    server_name "";
    return      444;
#    error_page   400 /400.html;
}
server {
...

===========
Данная конструкция работает только для "левых" Host, а для пустого Host возвращается ошибка 400.
Замена страницы "error_page 400 /400.html;" вместо return 444 работает нормально.

Change History (1)

comment:1 by Valentin V. Bartenev, 10 years ago

Resolution: invalid
Status: newclosed

Цитата из RFC 2616:

A client MUST include a Host header field in all HTTP/1.1 request
messages . If the requested URI does not include an Internet host
name for the service being requested, then the Host header field MUST
be given with an empty value. An HTTP/1.1 proxy MUST ensure that any
request message it forwards does contain an appropriate Host header
field that identifies the service being requested by the proxy. All
Internet-based HTTP/1.1 servers MUST respond with a 400 (Bad Request)
status code to any HTTP/1.1 request message which lacks a Host header
field.

С точки зрения протокола HTTP/1.1 такие запросы не являются корректными запросами, и сервер сразу же возвращает 400, не пытаясь обрабатывать некорректный запрос.

В документации речь шла о HTTP/1.0 и HTTP/0.9 запросах без заголовка Host. Такие запросы допустимы и обрабатываются сервером.

Note: See TracTickets for help on using tickets.