を持って、私はnginxのでpotential trailing hostname dot handling in two contextsと考えられてきたが、どちらか一方での使用が完全に正しい設定のために必要であるかどうか興味があった:nginxのサーバー名の正規表現と、「ホスト」は、ヘッダは末尾のドット
server_name ~^(\w+)\.(example\.com)\.?$;
if ($host ~ ^(\w*)\.(example\.com)\.?$) {
を持って、私はnginxのでpotential trailing hostname dot handling in two contextsと考えられてきたが、どちらか一方での使用が完全に正しい設定のために必要であるかどうか興味があった:nginxのサーバー名の正規表現と、「ホスト」は、ヘッダは末尾のドット
server_name ~^(\w+)\.(example\.com)\.?$;
if ($host ~ ^(\w*)\.(example\.com)\.?$) {
いいえ、それはどちらかのコンテキストでは必要ありません - nginxのは、自動的にの世話をします末尾のドットは、$host
variableのコンテキストと、server_name
directiveのコンテキストの両方であり、余分なドット(要求に存在する場合)を$http_host
variableに残します。
は、私はそれがhttp/ngx_http_request.c#ngx_http_validate_host
で実装されていると信じて:
1925 if (dot_pos == host_len - 1) {
1926 host_len--;
1927 }
それは、次の最小限の設定を確認することができます
:
server {
listen [::]:7325;
server_name ~^(\w*)\.?(example\.com\.?)$;
return 200 C:$2\tH:$host\tHH:$http_host\tSN:$server_name\n;
}
nginx/1.2.1
に対して次のテストを実行:
%printf 'GET/HTTP/1.0\nHost: head.example.com.\n\n' | nc localhost 7325 | fgrep example
C:example.com H:head.example.com HH:head.example.com. SN:~^(\w*)\.?(example\.com\.?)$
%
%printf 'GET http://line.example.com./ HTTP/1.0\n\n' | nc localhost 7325 | fgrep example
C:example.com H:line.example.com HH: SN:~^(\w*)\.?(example\.com\.?)$
%
%printf 'GET http://line.example.com./ HTTP/1.0\nHost: head.example.com.\n\n' | nc localhost 7325 | fgrep example
C:example.com H:line.example.com HH:head.example.com. SN:~^(\w*)\.?(example\.com\.?)$
%
注意してください、内部からの正規表現のキャプチャserver_name
ディレクティブまたは$host
変数には、末尾にドットがあります。したがって、上記の文脈でそれを説明するのは無意味です。