proxy_method

Sets the HTTP request method used by the proxy server when communicating with the backend. — NGINX HTTP Core

proxy_method
httpserverlocation
Синтаксисproxy_method method;
По умолчаниюnone
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументы1

Описание

The `proxy_method` directive in NGINX allows administrators to specify the HTTP method that the proxy will use when passing client requests to a proxied server. By default, NGINX uses the same method as the original client request (e.g., GET, POST). However, `proxy_method` allows customization by explicitly setting it to a method of choice, which can often be useful for specific application requirements or behaviors. Usage of this directive can vary based on the context in which it is defined: http, server, or location. For instance, in a location block, it can specify how to handle requests that match that location. The directive accepts a single argument that represents the desired HTTP method. Hence, it is important to ensure the method specified is supported by the proxied server to avoid unexpected behavior. When a request is proxied, this directive will override the default behavior and enforce the specified HTTP method on that request. This can be critical in scenarios where certain operations (like RESTful interactions) require a specific method which the client might not initially use, or when the request must conform to certain routing rules or practices determined by the backend application.

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

location /api { 
    proxy_pass http://backend; 
    proxy_method POST; 
}

Specifying an unsupported HTTP method can lead to errors from the proxied server.

If there is no back-end server that responds to the specified method, requests may fail 404 errors.

In some cases, clients may not expect the method to be altered, leading to confusion regarding API interactions.