nginx 反向代理之 proxy_pass


格式很簡單: proxy_pass URL;

其中URL包含:傳輸協議(http://, https://等)、主機名(域名或者IP:PORT)、uri。

 

示例如下:

proxy_pass http://www.xxx.com/;
proxy_pass http://192.168.200.101:8080/uri;
proxy_pass unix:/tmp/www.sock;

 

對於proxy_pass的配置有幾種情況需要注意:

 
         
假設server_name為www.xxx.com
當請求http://www.xxx.com/aming/a.html的時候,以上示例分別訪問的結果是
示例1:
location /aming/
{
    proxy_pass http://192.168.1.10;
    ...
}

結果1:http://192.168.1.10/aming/a.html

示例2:
location /aming/
{
    proxy_pass http://192.168.1.10/;
    ...
}

結果2:http://192.168.1.10/a.html
 示例3:
location /aming/
{
    proxy_pass http://192.168.1.10/linux/;
    ...
}
結果3:http://192.168.1.10/linux/a.html
 示例4:
location /aming/
{
    proxy_pass http://192.168.1.10/linux;
    ...
}

結果4:http://192.168.1.10/linuxa.html

 

總結:

為了方便記憶和規范配置,建議所有的 proxy_pass 后的url都以“/”結尾。
proxy_pass http://192.168.1.10/linux/;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM