Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions nginx/nginx.prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ http {

# ✅ HTTPS 서버 블록
server {
listen 443 ssl http2;
listen 443 ssl;
server_name kokomen.kr;

ssl_certificate /etc/letsencrypt/live/kokomen.kr/fullchain.pem;
Expand All @@ -44,13 +44,12 @@ http {

location / {
proxy_pass http://next-server/;
proxy_http_version 2.0;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_cache_bypass $http_upgrade;
Comment on lines +47 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

WebSocket 지원을 위한 헤더를 추가하면서 X-Forwarded-ForX-Forwarded-Proto 헤더가 제거되었습니다. 이 헤더들은 백엔드 애플리케이션(Next.js)이 클라이언트의 실제 IP 주소와 원래 요청 프로토콜(HTTPS)을 파악하는 데 매우 중요합니다.

  • X-Forwarded-For: 이 헤더가 없으면 백엔드에서 클라이언트 IP를 알 수 없어 로깅, 보안(예: IP 기반 접근 제어) 등에서 문제가 발생할 수 있습니다. 특히, nginx.conf 파일의 42번째 줄에 real_ip_header X-Forwarded-For;가 설정되어 있고, 56번째 줄의 로그 포맷에서도 $http_x_forwarded_for를 사용하고 있어 이 헤더는 필수적입니다.
  • X-Forwarded-Proto: 이 헤더는 백엔드가 리디렉션이나 URL 생성 시 올바른 프로토콜(https)을 사용하도록 보장합니다.

아래와 같이 해당 헤더들을 다시 추가하는 것을 권장합니다.

            proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection 'upgrade';
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_cache_bypass $http_upgrade;

}
}

Expand Down