proxy_pass

The `proxy_pass` directive forwards client requests to a specified proxied server. — NGINX HTTP Core

proxy_pass
locationif in locationlimit_except
Синтаксисproxy_pass URL;
По умолчаниюnone
Контекстlocation, if in location, limit_except
МодульNGINX HTTP Core
Аргументы1

Описание

The `proxy_pass` directive in NGINX is used to pass requests to a proxied server for processing. It allows the server to redirect traffic intended for a particular URI or location to another server, which can be an upstream server defined in the configuration or an external server specified with its address. When configured, if a client makes a request that matches the location block where the `proxy_pass` directive is used, NGINX will initiate a request to the upstream server. It does so by taking the original request and forwarding it to the server URI defined in the directive. The URL provided in the `proxy_pass` directive can be specified as either a protocol and host (e.g., `http://example.com`) or a full URL. Options can be provided further to manage how the request headers and request body are handled during the proxying process. The `proxy_pass` directive can significantly enhance the performance of your web application by distributing the traffic among multiple servers, allowing for load balancing and fault tolerance. However, it's vital to ensure proper configuration of additional directives (such as `proxy_set_header`) to maintain the integrity of request headers and enable features like WebSocket support and HTTP/2 tunneling.

Пример конфига

location /api/ {
    proxy_pass http://backend_server;
}

Ensure the upstream server is reachable, as failed connections will result in 502 Bad Gateway errors.

If the URL does not end with a slash, it may append the requested URI unexpectedly; careful path management is necessary.

Misconfigurations in caching and header forwarding may lead to unexpected client behavior.