location有定位的意思,根据uri来进行不同的定位,在虚拟主机中是必不可少的,location可以定位网站的不同部分,定位到不同的处理方式上。
精准匹配以=号为标志
location = /index.htm { root /var/www/html/; index index.htm index.html; } location = /index.htm { root html/; index index.htm index.html; } 精准匹配的优先级要优于一般匹配,所以重启nginx后会打开/var/www/html下面的index.htm而不会打开html下的index.htm正则匹配以~符号为标志
location / { root /usr/local/nginx/html; index index.html index.htm; } location ~ image { root /var/www/; index index.html; } 如果我们访问,http://localhost/image/logo.png 此时"/"与 location /匹配成功 此时"image"正则与"image/logo.png"也匹配成功?谁发挥作用呢? 正则表达式的成果将会使用,会覆盖前面的匹配 图片会真正的返回/var/www/image/logo.png转载于:https://www.cnblogs.com/lisqiong/p/11414082.html
相关资源:JAVA上百实例源码以及开源项目