Nginx引數proxy_pass細說
Syntax: |
proxy_pass URL; |
Default: |
— |
Context: |
location, if in location, limit_except |
Sets the protocol and address of a proxied(代理) server and an optional URI to which a location should be mapped. As a protocol, “http” or “https” can be specified. The address can be specified as a domain name or IP address, and an optional port:
proxy_pass http://localhost:8000/uri/;
or as a UNIX-domain socket path specified after the word “unix” and enclosed in colons:
proxy_pass http://unix:/tmp/backend.socket:/uri/;
If a domain name resolves to several addresses, all of them will be used in a round-robin fashion(流行). In addition, an address can be specified as a server group.
Parameter value can contain variables. In this case, if an address is specified as a domain name, the name is searched among the described server groups, and, if not found, is determined(確定) using a resolver(解析器).
A request URI is passed to the server as follows:
· If the proxy_pass directive(指令) is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location(location後匹配的路徑) is replaced by a URI specified in the directive:
解釋:如果在proxy_pass指令後的地址帶有uri,同時location後也帶有uri,這時在客戶端發出請求時,proxy_pass後的uri將覆蓋location後的uri向後端web伺服器發出請求。
location /name/ {
proxy_pass http://127.0.0.1/remote/;
}
例如這個示例中請求過程如下:
1、客戶請求 curl http://NG_IP:port/name/index.html -->2、Nginx代理伺服器 http://WEB_IP:port/remote/index.html --> 3、web伺服器
· If proxy_pass is specified without a URI, the request URI is passed to the server in the same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed URI:
解釋:如果proxy_pass沒有帶有uri,則使用原始的客戶端URI或location後指定的uri向後端web伺服器發出請求。
location /some/path/ {
proxy_pass http://127.0.0.1;
}
例如這個示例中請求過程如下:
1、客戶請求 curl http://NG_IP:port/some/path/index.html --> 2、Nginx代理伺服器 http://WEB_IP:port/some/path/index.html --> 3、web伺服器
Before version 1.1.12, if proxy_pass is specified without a URI, the original request URI might be passed instead of the changed URI in some cases.
In some cases, the part of a request URI to be replaced cannot be determined(確定):
· When location is specified using a regular expression, and also inside(裡面) named locations.
In these cases, proxy_pass should be specified without a URI.
解釋:如果location使用了正則,那麼proxy_pass後就不能指定uri.
· When the URI is changed inside a proxied location using the rewrite directive, and this same configuration will be used to process a request (break):
location /name/ {
rewrite /name/([^/]+) /users?name=$1 break;
proxy_pass http://127.0.0.1;
}
In this case, the URI specified in the directive is ignored and the full changed request URI is passed to the server.
解釋:當在location中使用rewrite規則修改URI時,proxy_pass後的URI就會被忽略,而使用rewrite修改後的uri來作為實際的請求。
· When variables are used in proxy_pass:
· location /name/ {
· proxy_pass http://127.0.0.1$request_uri;
· }
In this case, if URI is specified in the directive, it is passed to the server as is, replacing the original request URI.
WebSocket proxying requires special configuration and is supported since version 1.3.13.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23890223/viewspace-2147031/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- nginx location 和proxy_pass 代理說明Nginx
- Nginx的gzip配置引數說明Nginx
- 細說 rust 生命週期引數Rust
- JQuery Datatables Columns API 引數詳細說明jQueryAPI
- 細說函式返回值與引數函式
- nginx的反向代理proxy_pass指令Nginx
- docker – nginx – proxy_pass + proxy_redirectDockerNginx
- nginx 詳解 - 詳細配置說明Nginx
- nginx 詳解 – 詳細配置說明Nginx
- Nginx中proxy_pass的斜槓(/)問題Nginx
- Nginx之location中反向代理proxy_pass配置Nginx
- Nginx的proxy_pass簡單使用記錄Nginx
- nginx 常見引數以及重定向引數配置Nginx
- jquery datatables各引數詳細說明及簡單應用jQuery
- mysqldump引數說明MySql
- TOP引數說明
- Nginx編譯引數大全 configure引數中文詳解Nginx編譯
- nginx配置proxy_pass後斜槓的訪問Nginx
- Nginx location 和 proxy_pass路徑配置詳解Nginx
- 架構師細說NGINX的配置及優化架構Nginx優化
- Nginx 配置檔案引數詳解Nginx
- Oracle Table建立引數說明Oracle
- GoldenGate HANDLECOLLISIONS引數使用說明Go
- linux常用核心引數說明Linux
- nginx引數調優能提升多少效能Nginx
- Nginx伺服器常用引數設定Nginx伺服器
- nginx url必須攜帶引數判定Nginx
- Nginx 實戰-02-nginx proxy_pass 服務代理訪問 使用筆記 ubuntu nodejsNginx筆記UbuntuNodeJS
- expdp/impdp 詳細引數解釋
- mydumper和myloader引數使用說明
- 說說不知道的Golang中引數傳遞Golang
- 記錄一次 Nginx 配置 proxy_pass 後 返回404問題Nginx
- 函式解構引數小細節函式
- MySQL relay log 詳細引數解釋MySql
- Mysql my.cnf部分引數說明MySql
- /etc/sysctl.conf部分引數說明
- mysql relay log相關引數說明MySql
- Azure Blob (三)引數設定說明
- 所有初始化引數說明(轉)