Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed description of Nginx parameters proxy_pass

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Syntax:

Proxy_pass URL

Default:

-

Context:

Location, if in location, limit_except

Sets the protocol and address of a proxied (agent) 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 (popular). 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 (instruction) is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location (matching path after location) is replaced by a URI specified in the directive:

Explanation: if the address after the proxy_pass instruction has uri, and the address after location also has uri, when the client sends a request, the uri after proxy_pass will overwrite the uri after location and send a request to the backend web server.

Location / name/ {

Proxy_pass http://127.0.0.1/remote/;

}

For example, the request process in this example is as follows:

1. Customer request curl http://NG_IP:port/name/index.html-- > 2, Nginx proxy server http://WEB_IP:port/remote/index.html-- > 3, web server

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:

Explanation: if the proxy_pass does not have a uri, the request is made to the back-end web server using the uri specified after the original client URI or location.

Location / some/path/ {

Proxy_pass http://127.0.0.1;

}

For example, the request process in this example is as follows:

1. Customer request curl http://NG_IP:port/some/path/index.html-- > 2, Nginx proxy server http://WEB_IP:port/some/path/index.html-- > 3, web server

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 (OK):

When location is specified using a regular expression, and also inside (inside) named locations.

In these cases, proxy_pass should be specified without a URI.

Explanation: if location uses regular, then you cannot specify uri. Uri after proxy_pass.

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.

Explanation: when the rewrite rule is used in location to modify the URI, the URI after the proxy_pass is ignored and the rewrite modified uri is used as the actual request.

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 269

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report