Nginx經常使用配置

location & rewrite

(location =) > (location 完整路徑) > (location ^~ 路徑) > (location ~,~* 正則順序) > (location 部分起始路徑) > (/)
複製代碼

proxy_pass - 參考

在nginx中配置proxy_pass代理轉發時html

  • 若是在proxy_pass後面的url加/,表示絕對根路徑;
  • 若是沒有/,表示相對路徑,把匹配的路徑部分也給代理走。

假設下面四種狀況分別用 http://192.168.1.1/proxy/test.html 進行訪問。nginx

  1. 第一種:
# 代理到URL:http://127.0.0.1/test.html
location /proxy/ {
    proxy_pass http://127.0.0.1/;
}

複製代碼
  1. 第二種(相對於第一種,最後少一個 / )
# 代理到URL:http://127.0.0.1/proxy/test.html
location /proxy/ {
    proxy_pass http://127.0.0.1;
}

複製代碼
  1. 第三種:
# 代理到URL:http://127.0.0.1/aaa/test.html
location /proxy/ {
    proxy_pass http://127.0.0.1/aaa/;
}
複製代碼
  1. 第四種(相對於第三種,最後少一個 / )
# 代理到URL:http://127.0.0.1/aaatest.html
location /proxy/ {
    proxy_pass http://127.0.0.1/aaa;
}
複製代碼
相關文章
相關標籤/搜索