upstream backend {
server 192.168.0.100:80;
server 192.168.0.100:81;
}
server {
listen 80;
server_name www.abc.com abc.com;
root /opt/wwwroot/abc.com/;
location / {
proxy_pass https://backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_hide_header X-Powered-By;
}
location = / {
index index.html index.htm index.php;
}
}
我想当用户访问www.abc.com/ 的时候不走proxy_pass . 直接访问本地的/opt/wwwroot/abc.com/index.html 页面,其余的请求都走proxy_pass
搞了半天搞不定,有些怪异,求大神们帮忙看看。。
伊谢尔伦2017-05-16 17:30:20
这是nginx的默认location匹配规则导致的,nginx的location匹配的是相对URI,nginx的location匹配规则如下:
理解了nginx的location匹配规则,你的情况就很容易解释了,www.abc.com/的相对URI时/,首先时精确匹配location = / ,其他例如www.abc.com/adf的相对URI是/adf,根据你的location匹配规则交给了通用匹配
想解决这个问题将index放在通用匹配里就行了,单独写一个location = / {}从你的需求来看没有什么作用