프록시 환경에서 Express 사용
When running an Express app behind a reverse proxy, some of the Express APIs may return different values than expected. In order to adjust for this, the trust proxy
application setting may be used to expose information provided by the reverse proxy in the Express APIs. The most common issue is express APIs that expose the client’s IP address may instead show an internal IP address of the reverse proxy.
When configuring the trust proxy
setting, it is important to understand the exact setup of the reverse proxy. Since this setting will trust values provided in the request, it is important that the combination of the setting in Express matches how the reverse proxy operates.
프록시 뒤에서 Express 앱을 실행할 때는, (app.set()을 이용하여) 애플리케이션 변수 trust proxy
를 다음 표에 나열된 값 중 하나로 설정하십시오.
유형 | 값 |
---|---|
부울 |
When setting to |
IP addresses |
An IP address, subnet, or an array of IP addresses and subnets to trust as being a reverse proxy. The following list shows the pre-configured subnet names:
다음의 방법 중 하나로 IP 주소를 설정할 수 있습니다.
IP 주소 또는 서브넷이 지정되는 경우, 해당 IP 주소 또는 서브넷은 주소 결정 프로세스에서 제외되며, 신뢰할 수 있는 것으로 지정되지 않은 IP 주소 중 애플리케이션 서버에서 가장 가까운 IP 주소가 클라이언트의 IP 주소로 결정됩니다. This works by checking if |
숫자 |
Use the address that is at most When using this setting, it is important to ensure there are not multiple, different-length paths to the Express application such that the client can be less than the configured number of hops away, otherwise it may be possible for the client to provide any value. |
Function |
Custom trust implementation.
|
Enabling trust proxy
will have the following impact:
-
req.hostname의 값은
X-Forwarded-Host
헤더에 설정된 값으로부터 도출되며, 이 값은 클라이언트 또는 프록시에 의해 설정될 수 있습니다. -
https
인지,http
인지, 또는 잘못된 이름인지의 여부를 앱에 알리기 위하여 역방향 프록시가X-Forwarded-Proto
를 설정할 수 있습니다. 이 값에는 req.protocol이 반영됩니다.
trust proxy
설정은 proxy-addr 패키지를 이용해 구현됩니다. 자세한 정보는 해당 문서를 참조하십시오.