多个location有rewrite的时候需要注意在rewrite之后使用break可以避免多次location,rewrite之后的proxy_pass不会因break而失效。
server {
listen 80;
server_name localhost;
location /abc {
rewrite .* http://www.abc.com/$1 break;
proxy_pass http://www.proxy_pass.com;
}
location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
}
加了break会proxy_pass到www.proxy_pass.com
不加break会访问index.html