Цей документ може бути застарілим, в порівнянні з оригінальною англійською версією документації.

Express позаду проксі

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.


If true, the client’s IP address is understood as the left-most entry in the X-Forwarded-* header.

If false, the app is understood as directly facing the Internet and the client’s IP address is derived from req.connection.remoteAddress. This is the default setting.

IP addresses

An IP address, subnet, or an array of IP addresses and subnets to trust. The following list shows the pre-configured subnet names:

  • loopback -, ::1/128
  • linklocal -, fe80::/10
  • uniquelocal -,,, fc00::/7

You can set IP addresses in any of the following ways:

app.set('trust proxy', 'loopback') // specify a single subnet
app.set('trust proxy', 'loopback,') // specify a subnet and an address
app.set('trust proxy', 'loopback, linklocal, uniquelocal') // specify multiple subnets as CSV
app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']) // specify multiple subnets as an array

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.


Trust the nth hop from the front-facing proxy server as the client.


Custom trust implementation. Use this only if you know what you are doing.

app.set('trust proxy', function (ip) {
  if (ip === '' || ip === '') return true; // trusted IPs
  else return false;

Setting a non-false trust proxy value results in three important changes:

The trust proxy setting is implemented using the proxy-addr package. For more information, see its documentation.