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
9 changes: 5 additions & 4 deletions nginx/nginx.prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ http {

location / {
proxy_pass http://next-server/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_http_version 2.0;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
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;
Comment on lines +47 to +53
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

안녕하세요. Nginx 설정 변경에 대한 리뷰입니다. HTTP/2로 변경하고 프록시 헤더를 추가하는 좋은 시도이지만, 몇 가지 잠재적인 문제가 있어 의견을 남깁니다.

  1. HTTP/2 프록시 호환성: proxy_http_version2.0으로 설정하셨습니다. 하지만 proxy_passhttp://를 사용하고 있고, 업스트림 Next.js 서버(client:3000)는 HTTP/2 Cleartext(h2c)를 지원하지 않을 가능성이 높습니다. 이 경우 프록시 연결이 실패하여 서비스가 중단될 수 있습니다. 업스트림 서버가 명시적으로 h2c를 지원하도록 설정되지 않았다면, proxy_http_version1.1로 유지하는 것이 안전합니다.

  2. WebSocket 지원 누락: WebSocket 프록시에 필요한 UpgradeConnection 헤더 설정이 제거되었습니다. 만약 애플리케이션에서 WebSocket을 사용한다면 (예: 실시간 알림), 이 변경으로 인해 WebSocket 기능이 동작하지 않게 됩니다. Nginx와 백엔드 서버 간의 통신을 HTTP/1.1로 유지한다면, WebSocket을 지원하기 위해 이 헤더들을 다시 추가해야 합니다. 참고로, proxy_set_header Connection 'upgrade'; 대신 map 지시어를 사용하면 더 안정적으로 WebSocket 연결을 처리할 수 있습니다.

  3. 중복 헤더: proxy_set_header Host $host;가 이미 설정되어 있으므로 proxy_set_header X-Forwarded-Host $host;는 중복입니다. 대부분의 프레임워크는 Host 헤더를 우선적으로 사용하므로 X-Forwarded-Host는 제거해도 무방합니다.

아래와 같이 수정하여 안정성을 확보하고 WebSocket 지원을 유지하는 것을 제안합니다.

            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-Port $server_port;
            proxy_cache_bypass $http_upgrade;

}
}

Expand Down