Nginx location 配置

官方文檔 http://nginx.org/en/docs/http/ngx_http_core_module.html#location

location 末尾是否加 / 的區別

1. 末尾有’/’

location /proxy/ { #末尾有'/'
	proxy_pass http://127.0.0.1:8080/;
}

匹配以 /proxy/ 開頭的路徑。 eg: /proxy/aaa、/proxy/bbb、/proxy/aaa/bbb

  • 訪問 localhost:80/proxy/aaa,代理到 127.0.0.1:8080/aaa

2. 末尾無’/’

location /proxy { #末尾無'/'
	proxy_pass http://127.0.0.1:8080/;
}

匹配以 /proxy 開頭的路徑。 eg: /proxyaaa、/proxy/xxx/yyy、/proxy-xxx

  • 訪問 localhost:80/proxyaaa,代理到 127.0.0.1:8080/aaa
  • 訪問 localhost:80/proxy/aaa,代理到 127.0.0.1:8080//aaa (兩個 ‘//’)

end

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章