2011-03-08 18 views

Respuesta

205

Desde el HttpCoreModule docs:

  1. directivas con el signo "=" prefijo que coincida exactamente con la consulta. Si se encuentra, la búsqueda se detiene.
  2. Todas las demás directivas con cadenas convencionales. Si esta coincidencia usó el prefijo "^ ~", la búsqueda se detiene.
  3. Expresiones regulares, en el orden en que están definidas en el archivo de configuración.
  4. Si # 3 arrojó una coincidencia, ese resultado se utiliza. De lo contrario, se usa la coincidencia de # 2.

Ejemplo de la documentación:

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 ] 
} 

Si sigue siendo confuso, here's a longer explanation.

+0

@brablc Gracias, fijo. –

+4

con él puede ayudarle:) https://github.com/detailyang/nginx-location-match-visible – user2228392

+3

Tenga en cuenta que las reglas '/' y '/ documents /' coinciden con la solicitud '/ documents/index.html' , pero esta última regla tiene prioridad ya que es la regla más larga. –

11

Dispara en este orden.

  1. = (exactamente): Localización =/ruta
  2. ^~ (partido hacia adelante): ubicación^~/ruta
  3. ~ (expresión regular, no sensible): ubicación ~/ruta/
  4. ~ * (expresión regular, no sensible): ubicación ~ * (jpg | png | bmp)
  5. /:. Location/ruta