Nginxで一致するはずのlocation =/barはどのリクエストパスですか?
うまくいくもの:location /bar
これが私のnginx設定、ホストファイル設定、およびHTMLファイルです。
# cat /etc/nginx/sites-enabled/foo
server {
listen 80;
listen [::]:80;
server_name foo;
root /tmp/;
location /bar/ {
alias /var/www/foo/;
}
}
# cat /etc/hosts
127.0.0.1 localhost foo
127.0.1.1 debian
# cat /tmp/index.html
Hi! I am Tmp!
# cat /var/www/foo/index.html
<p>Hi! I am Index!</p>
# cat /var/www/foo/max.html
<p>Hi! I am Max!</p>
ルート、/ bar /、および/bar/max.htmlへのHTTPリクエストは、期待される結果を生成します 出力:
# systemctl restart nginx && curl http://foo/
Hi! I am Tmp!
# systemctl restart nginx && curl http://foo/bar/
<p>Hi! I am Index!</p>
# systemctl restart nginx && curl http://foo/bar/max.html
<p>Hi! I am Max!</p>
うまく動作しないもの:
location = /bar
今、設定を編集して
location /bar
を置き換えます
location = /bar
と
:
# cat /etc/nginx/sites-enabled/foo
server {
listen 80;
listen [::]:80;
server_name foo;
root /tmp/;
location = /bar/ {
alias /var/www/foo/;
}
}
# systemctl restart nginx && curl http://foo/
Hi! I am Tmp!
これらのHTTP要求は機能しなくなりました。
# systemctl restart nginx && curl http://foo/bar/
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.3</center>
</body>
</html>
# tail -n 1 /var/log/nginx/error.log
2018/05/25 00:07:50 [error] 29157#29157: *1 open() "/tmp/bar/index.html" failed (2: No such file or directory), client: 127.0.0.1, server: foo, request: "GET /bar/ HTTP/1.1", host: "foo"
# systemctl restart nginx && curl http://foo/bar
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.3</center>
</body>
</html>
# tail -n 1 /var/log/nginx/error.log
2018/05/25 00:08:49 [error] 29203#29203: *1 open() "/tmp/bar" failed (2: No such file or directory), client: 127.0.0.1, server: foo, request: "GET /bar HTTP/1.1", host: "foo"
# systemctl restart nginx && curl http://foo/bar/max.html
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.10.3</center>
</body>
</html>
# tail -n 1 /var/log/nginx/error.log
2018/05/25 00:10:10 [error] 29265#29265: *1 open() "/tmp/bar/max.html" failed (2: No such file or directory), client: 127.0.0.1, server: foo, request: "GET /bar/max.html HTTP/1.1", host: "foo"
GETがいずれかの
/bar
を要求しているようですまたは
/bar/
location = /bar/
と一致する指令?私はこれらのリクエストがこのディレクティブで動作するはずだと思ったhttp://nginx.org/en/docs/http/ngx_http_core_module.html#location 言及:
Also, using the “=” modifier it is possible to define an exact match of URI and location. If an exact match is found, the search terminates.
しかし、私の例で説明したように、うまくいかないようです?
location = /bar
と一致する要求の種類指令ですか?
回答 1 件
関連記事
- NGiNXロケーションフォルダーとロケーション正規表現のキャッシュパフォーマンス
- 正規表現を使用したNGinxロケーションディレクティブ
- リクエストURLパラメータをrecognize_pathを介してrailsルートと照合します
- nginx:ヘッダー値に基づいてリクエストにCookieを設定します
- ASPNET Core + Antiforgery + jQuery Ajax POST + Nginx:400不正な要求
- バイナリバッファリクエストの本文をNockと一致させる方法は?
- nginxディレクティブを使用して、別の場所でjpgを探します
- リクエストに一致する複数のアクションが見つかりました:***
URI
/bar/
index
に依存しています 指令内部的に URIを/bar/index.html
に書き換えます 。詳細については、このドキュメントを参照してください。完全一致
location
構文はのみ 元のURIと一致するじゃない 書き換えられたURI。nginx
デフォルトのlocation
を使用して、書き換えられたURIを処理します (構成では、これはserver
です 環境)。したがって、URI/bar/index.html
/tmp/bar/index.html
で検索されます 、見つかりません。