Heim  >  Artikel  >  Betrieb und Instandhaltung  >  Was ist der Nginx-Standort?

Was ist der Nginx-Standort?

(*-*)浩
(*-*)浩Original
2019-06-06 14:05:157047Durchsuche

Bei der Projektentwicklung stoßen wir häufig auf Nginx-Konfigurationsdateien. Es gibt viele Standortkonfigurationen, aber wir sind beunruhigt, weil wir ihre Bedeutung nicht verstehen können

Was ist der Nginx-Standort?

Location ist eine Blockanweisung in Nginx. Durch die Konfiguration des Location-Anweisungsblocks können Sie entscheiden, wie der vom Client gesendete Anforderungs-URI verarbeitet wird (ob er einer lokalen Datei zugeordnet oder weitergeleitet wird) und welcher Standort verarbeitet wird.

Grundlegende Syntax des Standorts

修饰符(modifier)         
location [ = | ~ | ~* | ^~ ]     uri     { ... } 
location根据不同的修饰符可以分为两大类
前缀location(prefix location): 
无修饰符的普通location
带=的精准匹配location
带^~的非正则表达式location
正则表达式location(regular expressions location):
~    区分大小写的正则location
~*   不区分大小写的正则location

Passendes Beispiel für den Standort:

ocation = / { [ configuration A ] }                     #用户请求"/"时,匹配A,例如:www.pcm.com/
location / { [ configuration B ] }                       #当用户请求"/index.html"时,匹配B,例如:www.pcm.com/index.html
location /documents/ { [ configuration C ] }             #当用户请求"/documents/"时,匹配C,例如:www.pcm.com/documents/index.html      
location ^~ /images/ { [ configuration D ] }             #当用户请求"/images/"时,匹配D,:www.pcm.com/images/1.jpg 
location ~* \.(gif|jpg|jpeg)$ { [ configuration E ] }    #当用户请求".gif|.jpg|.jpeg"时,匹配E,例如:www.pcm.com/documents/1.jpg
                                                         #上面的反斜杠是转义字符,$的意思是结尾

Das Folgende ist eine Standortkonfigurationsreferenz und die Regeln, die ausgeführt werden, wenn verschiedene Anforderungs-URIs Nginx erreichen

location / {
    [ configuration B ]
}

location /documents/ {
    [ configuration C ]
}

location ^~ /images/ {
    [ configuration D ]
}

location ~* \.(gif|jpg|jpeg)$ {
    [ configuration E ]
}

请求URI                        执行的规则
/                             A
/index.html                   B
/documents/document.html      C
/images/1.gif                 D
/documents/1.jpg              E

Weitere technische Artikel zu Nginx finden Sie in der Spalte Nginx-Tutorial, um mehr zu erfahren!

Das obige ist der detaillierte Inhalt vonWas ist der Nginx-Standort?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn