Nginx反向代理之proxy_pass指令
生活随笔
收集整理的這篇文章主要介紹了
Nginx反向代理之proxy_pass指令
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Nginx反向代理的配置語法
Nginx反向代理模塊的指令是由ngx_http_proxy_module模塊進行解析,該模塊在安裝Nginx的時候已經自己加裝到Nginx中了,接下來我們把反向代理中的常用指令一一介紹下:
proxy_pass proxy_set_header proxy_redirectproxy_pass
該指令用來設置被代理服務器地址,可以是主機名稱、IP地址加端口號形式。
| 默認值 | — |
| 位置 | location |
URL:為要設置的被代理服務器地址,包含傳輸協議(http,https://)、主機名稱或IP地址加端口號、URI等要素。
舉例:
proxy_pass http://www.baidu.com; location /server{} proxy_pass http://192.168.200.146;http://192.168.200.146/server/index.html proxy_pass http://192.168.200.146/;http://192.168.200.146/index.html大家在編寫proxy_pass的時候,后面的值要不要加"/"?
接下來通過例子來說明剛才我們提到的問題:
server {listen 80;server_name localhost;location /{#proxy_pass http://192.168.200.146;proxy_pass http://192.168.200.146/;} } 當客戶端訪問 http://localhost/index.html,效果是一樣的 server{listen 80;server_name localhost;location /server{#proxy_pass http://192.168.200.146;proxy_pass http://192.168.200.146/;} } 當客戶端訪問 http://localhost/server/index.html 這個時候,第一個proxy_pass就變成了http://localhost/server/index.html 第二個proxy_pass就變成了http://localhost/index.html效果就不一樣了。總結
以上是生活随笔為你收集整理的Nginx反向代理之proxy_pass指令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx正向代理实现
- 下一篇: Nginx反向代理之proxy_set_