When running an Express app behind a proxy, set (by using app.set()) the application variable
trust proxy to one of the values listed in the following table.
Although the app will not fail to run if the application variable
trust proxy is not set, it will incorrectly register the proxy’s IP address as the client IP address unless
trust proxy is configured.
An IP address, subnet, or an array of IP addresses and subnets to trust. The following list shows the pre-configured subnet names:
You can set IP addresses in any of the following ways:
When specified, the IP addresses or the subnets are excluded from the address determination process, and the untrusted IP address nearest to the application server is determined as the client’s IP address.
Custom trust implementation. Use this only if you know what you are doing.
trust proxy will have the following impact:
The value of req.hostname is derived from the value set in the
X-Forwarded-Host header, which can be set by the client or by the proxy.
X-Forwarded-Proto can be set by the reverse proxy to tell the app whether it is
http or even an invalid name. This value is reflected by req.protocol.
trust proxy setting is implemented using the proxy-addr package. For more information, see its documentation.