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;
}
}
I want the user not to use proxy_pass when visiting www.abc.com/. Instead, they can directly access the local /opt/wwwroot/abc.com/index.html page, and all other requests will go through proxy_pass
I've been working on it for a long time and I can't figure it out. It's a little weird. Please help me. .
This is caused by the default location matching rules of nginx. The location matching of nginx matches relative URI. The location matching rules of nginx are as follows:
Understanding the location matching rules of nginx, your situation is easy to explain. The relative URI of www.abc.com/ is /. First, it accurately matches location = /. Other relative URIs such as www.abc.com/adf It is /adf, and it is handed over to universal matching according to your location matching rules
If you want to solve this problem, just put the index in the universal matching. Writing a separate location = / {} has no effect according to your needs
If the location below is not needed, just index index.html; that’s it.
Replace the two locations. . .