首页 > Linux操作系统 > Linux操作系统 > Nginx参数proxy_pass细说


原创 Linux操作系统 作者:1向2飞 时间:2017-11-09 13:46:15 0 删除 编辑


proxy_pass URL;



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:


location /name/ {




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:


location /some/path/ {




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.


·         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;



In this case, the URI specified in the directive is ignored and the full changed request URI is passed to the server.


·         When variables are used in proxy_pass:

·         location /name/ {

·             proxy_pass$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博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

下一篇: SSL certificate chains


  • 博文量
  • 访问量