ホームページ  >  記事  >  運用・保守  >  nginxの場所でuriをインターセプトする方法

nginxの場所でuriをインターセプトする方法

王林
王林転載
2023-05-18 12:07:061572ブラウズ

説明:

場所の root および alias

  • root コマンドは、検索されたルートをルート設定ディレクトリに設定するだけです。つまり、uri は切り詰められませんが、元の uri を使用してディレクトリにジャンプしてファイルを見つけます。

  • ais コマンドは一致する uri を切り詰めてから、次を使用します。追加するエイリアスによって設定されたパス 残りの URI をサブパスとして検索します

location proxy_pass の uri

proxy_pass URL に uri がない場合

  • 末尾が「/」の場合、一致する URI は切り詰められます

  • #末尾が「/」でない場合、一致する URI は切り詰められませんtruncated

proxy_pass の URL に URI が含まれている場合、一致する URI は切り捨てられます

examples

##root## の場所
#

root@pts/1 $ ls -ld /data/web/lctest*|awk '{print $nf}'
/data/web/lctest
/data/web/lctest2
/data/web/lctest3
/data/web/lctest4


location /lctest {
  root /data/web/;
}

location /lctest2/ {
  root /data/web/;
}
location /lctest3 {
  root /data/web;
}
location /lctest4/ {
  root /data/web;
}

curl テストの結果は次のとおりです

注: ブラウザーが / を追加しない場合は、 end と入力すると自動的に追加されますが、curl No

root@pts/1 $ curl http://tapi.xxxx.com/lctest/
hello world

root@pts/1 $ curl http://tapi.xxxx.com/lctest2/
hello world
2

root@pts/1 $ curl http://tapi.xxxx.com/lctest3/
3
hello world

root@pts/1 $ curl http://tapi.xxxx.com/lctest4/
hello world
4

location alias

location /lctest5 {
  alias /data/web/;
}
location /lctest6/ {
  alias /data/web/;
}

location /lctest7 {
  alias /data/web;
}

## 403 /data/web forbidden
location /lctest8/ {
  alias /data/web;
}

curl テスト結果は以下の通りです

curl 'http://tapi.kaishustory.com/lctest5/'
curl 'http://tapi.kaishustory.com/lctest6/'
curl 'http://tapi.kaishustory.com/lctest7/'
结果都是 /data/web/index.html的输出

root@pts/1 $ curl 'http://tapi.kaishustory.com/lctest8/'
<html>
<head><title>403 forbidden</title></head>
<body bgcolor="white">
<center><h1>403 forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>

location proxy_pass

#--------proxy_pass配置---------------------
location /t1/ { proxy_pass http://servers; }  #正常,不截断
location /t2/ { proxy_pass http://servers/; }  #正常,截断
location /t3 { proxy_pass http://servers; }  #正常,不截断
location /t4 { proxy_pass http://servers/; }  #正常,截断
location /t5/ { proxy_pass http://servers/test/; }  #正常,截断
location /t6/ { proxy_pass http://servers/test; }  #缺"/",截断
location /t7 { proxy_pass http://servers/test/; }  #含"//",截断
location /t8 { proxy_pass http://servers/test; }  #正常,截断

テスト スクリプト

for i in $(seq 8)
do
  url=http://tapi.xxxx.com/t$i/doc/index.html
  echo "-----------$url-----------"
  curl url
done

テスト結果えー

以上がnginxの場所でuriをインターセプトする方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はyisu.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。