- 快速入门
- 指南
- 参考手册
- 高级主题
- 资源
- Express 词汇表
- Express 社区
- 模板引擎
- Express 中间件
- Express body-parser middleware
- Express compression middleware
- Express connect-rid middleware
- Express cookie-parser middleware
- Express cookie-session middleware
- Express cors middleware
- Express csurf middleware
- Express errorhandler middleware
- Express method-override middleware
- Express morgan middleware
- Express multer middleware
- Express response-time middleware
- Express serve-favicon middleware
- Express serve-index middleware
- Express serve-static middleware
- Express session middleware
- Express timeout middleware
- Express vhost middleware
- Express 实用模板
- 推荐框架
- 推荐书籍和博客
为 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.
Type | Value |
---|---|
Boolean | If If |
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:
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. |
Number | Trust the |
Function | Custom trust implementation. Use this only if you know what you are doing.
|
Enabling 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 ishttps
orhttp
or even an invalid name. This value is reflected by req.protocol.The req.ip and req.ips values are populated with the list of addresses from
X-Forwarded-For
.
The trust proxy
setting is implemented using the proxy-addr package. For more information, see its documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论