일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- AWS
- docker-compose
- java
- rsa충돌
- 페이지이동경고
- byungjoo kim
- 김병주
- failed upgrade header
- 커리어스킬
- GIT
- Spring
- docker
- WebSocket
- alpine
- nginx
- iTerm2
- gcOverhead
- beforeunload
- omz
- zsh
- SSH
- Dominic
- Intellij
- python
- KPT
- handshake
- MSA
- socjs
- remote
- 토이프로젝트
Archives
- Today
- Total
Eyeeshot BloG
ELB Websocket 설정 문제 본문
ELB 상황에서 Websocket 을 사용하려면 문제가 몇가지 있다 우선 ELB 에 proxy 설정을 통해 websocket 연결이 가능하게 할수 있다. 링크
하지만 이렇게 연결하더라고 STOMP + SockJS 로 사용하려면 during WebSocket handshake: Unexpected response code: 400 에러가 난다.
해당 오류는 Handshake failed due to invalid Upgrade header 오류로 헤더 정보에 upgrade 정보가 없어서 나오는 에러이다.
ELB proxy policy 는 proxy만 가능하고 헤더정보는 여전히 넘어오지 않는다. 따라서 우회하는 방법으로
ELB -> nginx -> application 처리로 테스트 해보았다.
nginx는 docker-compose 로 아래와 같이 설정하였다.
docker-compose.yml
version: '3'
services:
proxy:
image: nginx:latest
ports:
- "80:80"
- "443:443"
- "9999:9999"
- "5400:5400"
volumes:
- ./proxy/nginx.conf:/etc/nginx/nginx.conf
web:
image: nginx:latest
expose:
- "8080"
volumes:
- ./source:/source
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
php:
image: php:7.3-fpm
expose:
- "9000"
volumes:
- ./source:/source
web, php 는 해당 docker 정상 동작 확인용으로 같이 올렸다.
nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
# include /etc/nginx/mime.types;
# default_type application/octet-stream;
# upstream docker-nginx {
# server web:8080;
# }
server {
listen 5400;
server_name localhost;
location / {
proxy_pass http://{설정할 IP}:35400;
}
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://{설정할 IP}:35100;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /ws/ {
proxy_pass http://{설정할 IP}:35100;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
}
}
server {
listen 443;
server_name _;
location /ws/ {
proxy_pass http://{설정할 IP}:35100;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
}
location / {
proxy_pass http://{설정할 IP}:35100;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'upgrade - "$http_upgrade"'
'header - "$upstream_http_custom_header"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
아래 코드 부분이 프록시로 전달되면서 헤더 정보를 추가 입력해 전달하게된다
proxy_pass http://{설정할 IP}:35100;
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
이렇게하면 Handshake failed due to invalid Upgrade header 오류가 더이상 안나게된다..
더 좋은방법이 있을꺼 같지만...현재로서는 찾은방법은 여기까지이다.
'Tech' 카테고리의 다른 글
vi 에서 붙여넣기 했을때 탭 깨지는 현상 해결방법 (0) | 2021.01.11 |
---|---|
SSH 접속시 RSA 공유키 충돌 해결방법 (0) | 2020.12.03 |
Sping boot + websocket Hands On (0) | 2020.12.03 |
Spring WebSocket (0) | 2020.12.03 |
Mac OS 에 기본 설정 하기 (0) | 2020.04.12 |