proxy_bind

The proxy_bind directive configures the local IP address for outgoing connections to the proxied server. — NGINX HTTP Core

proxy_bind
httpserverlocation
Синтаксисproxy_bind address [ port ];
По умолчаниюnone
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументы1-2

Описание

The `proxy_bind` directive is used in NGINX to specify which local IP address should be used for outgoing connections to proxied servers. This can be particularly useful in environments where multiple IP addresses are assigned to an interface, and the administrator wishes to control which IP address is utilized when NGINX makes outbound requests. The directive accepts one or two parameters: the first parameter is the local IP address to bind to, and the optional second parameter can specify which port to use. If the second parameter is provided, NGINX binds to that specific port when connecting to the upstream server. When `proxy_bind` is used, the IP address provided will be set in the `SO_BINDTODEVICE` socket option, influencing the routing of outbound packets. This ensures that connections initiated by NGINX to the proxied host will appear to come from the specified IP address rather than the default one. It's essential to ensure that the IP address is assigned to one of the server’s network interfaces, or else connection attempts may fail. Additionally, you should consider that using an incorrect IP address could lead to routing issues, especially in a multi-homed environment where multiple interfaces are present. In summary, `proxy_bind` is an advanced directive aimed at users who need fine-grained control over their server's network behavior, particularly in complex networking setups or when integrating with external services that require traffic originating from a specific IP address.

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

location / { 
    proxy_pass http://backend;
    proxy_bind 192.168.1.100; 
}

Ensure the specified IP address is configured on the NGINX server.

If using a port, ensure it is not in use by other services to prevent binding errors.

Using `proxy_bind` without appropriate flow monitoring can lead to mismatched expectations of traffic routing.