Original address: https://www.nginx.com/resources/admin-guide/reverse-proxy/
Original title: Choosing an Outgoing IP Address
If your proxy server has multiple network interfaces, sometimes you may need to select a specific source IP address to connect to the proxy server or upstream server. This configuration can come in handy if a proxy server behind NGINX is set up to only accept connections from a specific IP network or IP address range.
If your proxy server has several network interfaces, sometimes you might need to choose a particular source IP address for connecting to a proxied server or an upstream. This may be useful if a proxied server behind NGINX is configured to accept connections from particular IP networks or IP address ranges.
Specify the proxy_bind
directive and set the IP address of the network interface:
Specify the proxy_bind directive and the IP address of the necessary network interface:
<code>location <span>/app1/</span> { proxy_bind <span>127.0</span><span>.0</span><span>.1</span>; proxy_pass <span>http</span>:<span>//</span>example.com<span>/app1/</span>; }</code>
<code>location <span>/app2/</span> { proxy_bind <span>127.0</span><span>.0</span><span>.2</span>; proxy_pass <span>http</span>:<span>//</span>example.com<span>/app2/</span>; }</code>
The IP address can also be specified using variables. For example, the $server_addr
variable passes the IP address of the network interface that received the request.
The IP address can be also specified with a variable. For example, the $server_addr variable passes the IP address of the network interface that accepted the request:
<code>location /app3/ { proxy_<span>bind</span><span>$server_addr</span>; proxy_pass http://example.com/app3/; }</code>
The above introduces the NGINX study notes - Choosing an Outgoing IP Address, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.