>  기사  >  운영 및 유지보수  >  nginx 위치에서 uri를 가로채는 방법

nginx 위치에서 uri를 가로채는 방법

王林
王林앞으로
2023-05-18 12:07:061570검색

설명:

location

  • root 명령의 루트 및 별칭은 검색 루트를 루트가 설정한 디렉터리로만 설정합니다. 즉, URI는 잘리지 않지만 원래 URI는 다음 용도로 사용됩니다. 검색할 디렉터리로 이동합니다.

  • aias 파일 명령은 일치하는 uri를 잘라낸 다음 별칭으로 설정된 경로와 나머지 uri를 하위 경로로 사용하여

    위치에서 Proxy_pass의 uri를 찾습니다. uri가 포함되어 있지 않습니다

꼬리가 "/"이면 일치하는 uri가 잘립니다.

  • 꼬리가 "/"가 아니면 일치하는 uri가 잘리지 않습니다

  • 다음의 URL이 Proxy_pass에 uri가 있으면 잘립니다. 일치하는 uri

루트의 위치

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 테스트 결과는 다음과 같습니다

참고: 브라우저가 /를 추가하지 않는 경우 입력 할 때 종료하면 자동으로 추가되지만 Curl Nope

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>

테스트 결과

#--------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; }  #正常,截断

위 내용은 nginx 위치에서 uri를 가로채는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 yisu.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제