programing tip

Nginx 위치 우선 순위

itbloger 2020. 6. 3. 21:26
반응형

Nginx 위치 우선 순위


위치 지시문은 어떤 순서로 실행됩니까?


로부터 HttpCoreModule 워드 프로세서 :

  1. 쿼리와 정확히 일치하는 "="접두사를 가진 지시문 발견되면 검색이 중지됩니다.
  2. 기존 문자열이있는 나머지 모든 지시문. 이 일치가 "^ ~"접두사를 사용한 경우 검색이 중지됩니다.
  3. 구성 파일에 정의 된 순서대로 정규식.
  4. # 3이 일치하면 해당 결과가 사용됩니다. 그렇지 않으면 # 2의 일치 항목이 사용됩니다.

설명서의 예 :

location  = / {
  # matches the query / only.
  [ configuration A ] 
}
location  / {
  # matches any query, since all queries begin with /, but regular
  # expressions and any longer conventional blocks will be
  # matched first.
  [ configuration B ] 
}
location /documents/ {
  # matches any query beginning with /documents/ and continues searching,
  # so regular expressions will be checked. This will be matched only if
  # regular expressions don't find a match.
  [ configuration C ] 
}
location ^~ /images/ {
  # matches any query beginning with /images/ and halts searching,
  # so regular expressions will not be checked.
  [ configuration D ] 
}
location ~* \.(gif|jpg|jpeg)$ {
  # matches any request ending in gif, jpg, or jpeg. However, all
  # requests to the /images/ directory will be handled by
  # Configuration D.   
  [ configuration E ] 
}

여전히 혼란 스러우면 더 자세한 설명이 있습니다.


이 순서대로 실행됩니다.

  1. = (바로 그거죠)

    location = /path

  2. ^~ (앞으로 일치)

    location ^~ /path

  3. ~ (정규 표현 대소 문자 구분)

    location ~ /path/

  4. ~* (정규 표현식은 대소 문자를 구분하지 않습니다)

    location ~* .(jpg|png|bmp)

  5. /

    location /path

참고 URL : https://stackoverflow.com/questions/5238377/nginx-location-priority

반응형