Nginx 的代理功能是通過 ngx_http_proxy_module 模塊來實現的。默認在安裝 Nginx 時已經安裝了ngx_http_proxy_module模
塊,因此可直接使用 ngx_http_proxy_module 模塊。
21.1、ngx_http_proxy_module模塊介紹:
1、proxy_pass 屬於 ngx_http_proxy_module 模塊,此模塊可以將請求轉發到另一台服務器,在實際的反向代理工作中,
會通過 location 功能匹配指定的 URI,然后把接收到的符合匹配 URI 的請求通過 proxy_pass 拋給定義好的upstream節
點池。
2、官網地址:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
3、官網 proxy_pass 使用案例:
(1)將匹配 URI 為 name 的請求拋給 http://127.0.0.1/remote/:
location /name/ {
proxy_pass http://127.0.0.1/remote/;
}
(2)將匹配 URI 為 some/path 的請求拋給 http://127.0.0.1:
location /some/path/ {
proxy_pass http://127.0.0.1;
}
(3)將匹配 URI 為 name 的請求應用指定的 rewrite 規則,然后拋給 http://127.0.0.1:
location /name/ {
rewrite /name/([^/]+) /users?name=$1 break;
proxy_pass http://127.0.0.1;
}
21.2、ngx_http_proxy_module模塊參數說明: