Nginx配置proxy_pass

nginx配置proxy_pass,須要注意轉發的路徑配置 nginx

 
 
 
 
1location /test/ { proxy_pass http://t6:8300; } 2location /test/ { proxy_pass http://t6:8300/; }

上面兩種配置,區別只在於proxy_pass轉發的路徑後是否帶 「/」 jsp

針對狀況1

  1. 若是訪問url = http://server/test/test.jsp,則被nginx代理後;
  2. 請求路徑會便問http://proxy_pass/test/test.jsp
  3. 將test/ 做爲根路徑,請求test/路徑下的資源;

針對狀況2

  1. 若是訪問url = http://server/test/test.jsp,則被nginx代理後;
  2. 請求路徑會變爲 http://proxy_pass/test.jsp
  3. 直接訪問server的根資源;

典型實例:

同一個域名下,根據根路徑的不一樣,訪問不一樣應用及資源
例如:url

A 應用和 B應用共同使用訪問域名 http://serverspa

應用 域名 配置 效果
http://server/a http://server 狀況2 致使訪問http://server/a/test.jsp時,代理到http://proxy_pass/test.jsp
致使沒法訪問到正確的資源,頁面中若是有對根資源的訪問,
也都會以http://server 作爲根路徑訪問資源,致使資源失效
http://server/b http://server 狀況1 保證代理後正確有效


相關文章
相關標籤/搜索