nginx로 websocket 서버 리버스 프록시하기

노력을 즐기는 사람·2020년 10월 15일
1
post-thumbnail

참고문서
튜터링을 진행하기 위해서 java-notebook 을 우분투에 설치하고 외부로 공개했다. 그 과정에서 reverse-proxy를 nginx로 구성했는데 Websocket : Error during WebSocket handshake: Unexpected response code: 504 이런 오류가 발생했다.
해결법은 다음과 같다

본인이 reverse-proxy를 구성한 conf파일에서 location 안에 아래 4줄을 추가하자

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;

왜 되는지는 모르겠지만 어쨌든 된다.

server {
        server_name java.prayme.ga;

        access_log /var/log/nginx/reverse-access.log;
        error_log /var/log/nginx/reverse-error.log;

        location / {
                proxy_pass http://localhost:8888;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $host;
        }
}
profile
노력하는 자는 즐기는 자를 이길 수 없다

0개의 댓글