๐ fix: Nginx Forwarded-IP ์ ๋ฌ ์ค์ ๋ฐ ์ฑํ ๋ ์ง ์๋ฆผ ๋ก์ง ์์ #312
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
๐จ ํ ์คํฌ
๐ ์์ ๋ด์ฉ
Nginx ์ค์ ํ์ผ์ IP ๊ด๋ จ ํค๋ ์ ๋ฌ ์ค์ ์ถ๊ฐ
https://developer.mozilla.org/ko/docs/Web/HTTP/Headers/X-Forwarded-For
X-Real-IP
ํค๋ : ํด๋ผ์ด์ธํธ์ ์ค์ IP ์ฃผ์๋ฅผ ๋จ์ผ ๊ฐ์ผ๋ก ์ ๋ฌ ํ๋ ํค๋. ํ๋ก์ ์๋ฒ๊ฐ ์ค์ IP๋ฅผ ๋ฐฑ์๋ ์๋ฒ์ ์ ๋ฌํ๋ ์ฉ๋๋ก ์ฃผ๋ก ์ฌ์ฉ๋จ. (์๋ฏธ์์ผ๋ก๋ ๋ฐ๋ก ์ง์ ์ IP ์ฃผ์ ๊ฐ ๋ง๋๊ฑฐ ๊ฐ๊ธดํ๋ฐ, ์ด๊ฑด ํ์ค์ ์๋ ๊ฒ ๊ฐ์์ ์ผ๋จ ์ด๋ ๊ฒ ์ค์ ํด๋์์ต๋๋ค. ๐ )X-Forwarded-For
ํค๋ : ํด๋ผ์ด์ธํธ์ IP ์ฃผ์๋ฟ๋ง ์๋๋ผ ์์ฒญ์ด ๊ฑฐ์ณ์จ ๋ชจ๋ ํ๋ก์ ์๋ฒ์ IP ์ฃผ์๋ฅผ ๋ชฉ๋ก ํ์์ผ๋ก ์ ๋ฌํ๋ ํค๋.X-Forwarded-Proto
ํค๋ : ํด๋ผ์ด์ธํธ์ ํ๋กํ ์ฝ์ ์ ๋ฌํ๋ ํค๋.์๋ฒ ๋ด IP ํ๋ ๋ก์ง ์์
CF-Connecting-IP
๋ CloudFlare์์ ์ฌ์ฉํ๋ ํค๋๋ก, ์ด์ ์ฌ์ฉ๋์ง ์๊ธฐ์ ์ ๊ฑฐํ์์ต๋๋ค.๋ํ,
request.socket?.remoteAddress
์ญ์ Nginx์์ ์์ผ ์ฐ๊ฒฐ์์๋X-Forwarded-For
ํค๋๋ฅผ ์ค์ ํด๋๋๋ก ํ์์ผ๋ฏ๋ก ํ์์์ด ์ ๊ฑฐ ํ์์ต๋๋ค.์ฑํ ์ค๋ฅ ๊ฐ์ ์ ์ํ await ํค์๋ ์ถ๊ฐ
๊ธฐ์กด์ ๋ ์ง ์๋ฆผ๋ณด๋ค ์ฑํ ์ด ๋จผ์ emit ๋๋ ๋ฌธ์ ๊ฐ ์์ด, ํด๋น ๋ฉ์์ง๊ฐ ํด๋น์ผ ์ต์ด ๋ฉ์์ง์ธ์ง ํ์ธ ํ ๋ ์ง ์๋ฆผ์ ๋ฐํํ๋ ๋ถ๋ถ์ await์ ์ถ๊ฐํ์ฌ ์์๋ฅผ ๋ณด์ฅํ ์ ์๋๋ก ์ฒ๋ฆฌํ์์ต๋๋ค.