Skip to content

Commit 1cd50d4

Browse files
authored
fix: Nginx가 WebSocket Handshake 요청을 올바르게 처리하도록 (#481)
* fix: nginx가 웹소켓 핸드셰이크 요청을 제대로 처리하도록 수정 * chore: 변경된 nginx.conf가 cd 단계에서 개발 서버에 반영되도록 - 서버에 존재하는 default를 nginx.conf에 통합 * test: 테스트 코드 수정 - 초기 핸드셰이크는 ws가 아니라 http 프로토콜을 사용함 - 핸드셰이크를 테스트하므로 목적에 맞게 클래스 이름 변경 * chore: docker-compose down 시 명시적인 yml을 사용하도록 * chore: nginx conf 파일 환경 분리 * chore: prod 환경에서 cd 스크립트 수행 시 nginx conf 파일이 적용되도록 - docker compose down 시 명시적으로 yml 파일 지정
1 parent 4329673 commit 1cd50d4

File tree

5 files changed

+80
-11
lines changed

5 files changed

+80
-11
lines changed

.github/workflows/dev-cd.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,28 @@ jobs:
7171
source: "./docs/infra-config/config.alloy"
7272
target: "/home/${{ secrets.DEV_USERNAME }}/solid-connection-dev/"
7373

74-
- name: Run docker compose
74+
- name: Copy nginx config to remote
75+
uses: appleboy/scp-action@master
76+
with:
77+
host: ${{ secrets.DEV_HOST }}
78+
username: ${{ secrets.DEV_USERNAME }}
79+
key: ${{ secrets.DEV_PRIVATE_KEY }}
80+
source: "./docs/infra-config/nginx.dev.conf"
81+
target: "/home/${{ secrets.DEV_USERNAME }}/solid-connection-dev/nginx"
82+
rename: "default.conf"
83+
84+
- name: Run docker compose and apply nginx config
7585
uses: appleboy/ssh-action@master
7686
with:
7787
host: ${{ secrets.DEV_HOST }}
7888
username: ${{ secrets.DEV_USERNAME }}
7989
key: ${{ secrets.DEV_PRIVATE_KEY }}
8090
script_stop: true
8191
script: |
92+
sudo cp /home/${{ secrets.DEV_USERNAME }}/solid-connection-dev/nginx/default.conf /etc/nginx/conf.d/default.conf
93+
sudo nginx -t
94+
sudo nginx -s reload
95+
8296
cd /home/${{ secrets.DEV_USERNAME }}/solid-connection-dev
83-
docker compose down
97+
docker compose -f docker-compose.dev.yml down
8498
docker compose -f docker-compose.dev.yml up -d --build

.github/workflows/prod-cd.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,28 @@ jobs:
7171
source: "./docs/infra-config/config.alloy"
7272
target: "/home/${{ secrets.USERNAME }}/solid-connect-server/"
7373

74-
- name: Run docker compose
74+
- name: Copy nginx config to remote
75+
uses: appleboy/scp-action@master
76+
with:
77+
host: ${{ secrets.HOST }}
78+
username: ${{ secrets.USERNAME }}
79+
key: ${{ secrets.PRIVATE_KEY }}
80+
source: "./docs/infra-config/nginx.prod.conf"
81+
target: "/home/${{ secrets.USERNAME }}/solid-connection-prod/nginx"
82+
rename: "default.conf"
83+
84+
- name: Run docker compose and apply nginx config
7585
uses: appleboy/ssh-action@master
7686
with:
7787
host: ${{ secrets.HOST }}
7888
username: ${{ secrets.USERNAME }}
7989
key: ${{ secrets.PRIVATE_KEY }}
8090
script_stop: true
8191
script: |
92+
sudo cp /home/${{ secrets.USERNAME }}/solid-connection-prod/nginx/default.conf /etc/nginx/conf.d/default.conf
93+
sudo nginx -t
94+
sudo nginx -s reload
95+
8296
cd /home/${{ secrets.USERNAME }}/solid-connect-server
83-
docker compose down
97+
docker compose -f docker-compose.prod.yml down
8498
docker compose -f docker-compose.prod.yml up -d --build
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
server {
22
listen 80;
3+
server_name api.stage.solid-connection.com;
34

45
# http를 사용하는 경우 주석 해제
56
# location / {
@@ -17,9 +18,10 @@ server {
1718

1819
server {
1920
listen 443 ssl;
21+
server_name api.stage.solid-connection.com;
2022

21-
ssl_certificate /etc/letsencrypt/live/api.solid-connection.com/fullchain.pem;
22-
ssl_certificate_key /etc/letsencrypt/live/api.solid-connection.com/privkey.pem;
23+
ssl_certificate /etc/letsencrypt/live/api.stage.solid-connection.com/fullchain.pem;
24+
ssl_certificate_key /etc/letsencrypt/live/api.stage.solid-connection.com/privkey.pem;
2325
client_max_body_size 10M;
2426

2527
ssl_protocols TLSv1.2 TLSv1.3;
@@ -31,10 +33,13 @@ server {
3133
ssl_stapling_verify on;
3234

3335
location / {
34-
proxy_pass http://solid-connection-server:8080;
36+
proxy_pass http://localhost:8080;
3537
proxy_set_header Host $host;
3638
proxy_set_header X-Real-IP $remote_addr;
3739
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
3840
proxy_set_header X-Forwarded-Proto $scheme;
41+
proxy_http_version 1.1;
42+
proxy_set_header Upgrade $http_upgrade;
43+
proxy_set_header Connection "upgrade";
3944
}
40-
}
45+
}

docs/infra-config/nginx.prod.conf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
server {
2+
listen 80;
3+
server_name api.solid-connection.com;
4+
5+
location / {
6+
return 301 https://$host$request_uri;
7+
}
8+
}
9+
10+
server {
11+
listen 443 ssl;
12+
server_name api.solid-connection.com;
13+
14+
ssl_certificate /etc/letsencrypt/live/api.solid-connection.com/fullchain.pem;
15+
ssl_certificate_key /etc/letsencrypt/live/api.solid-connection.com/privkey.pem;
16+
client_max_body_size 10M;
17+
18+
ssl_protocols TLSv1.2 TLSv1.3;
19+
ssl_prefer_server_ciphers on; # 클라이언트 보다 서버의 암호화 알고리즘을 우선하도록 설정
20+
ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256";
21+
ssl_session_cache shared:SSL:10m; # SSL 세션 캐시 설정
22+
ssl_session_timeout 10m;
23+
ssl_stapling on; # OCSP 스테이플링 활성화
24+
ssl_stapling_verify on;
25+
26+
location / {
27+
proxy_pass http://127.0.0.1:8080;
28+
proxy_set_header Host $host;
29+
proxy_set_header X-Real-IP $remote_addr;
30+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
31+
proxy_set_header X-Forwarded-Proto $scheme;
32+
proxy_http_version 1.1;
33+
proxy_set_header Upgrade $http_upgrade;
34+
proxy_set_header Connection "upgrade";
35+
}
36+
}

src/test/java/com/example/solidconnection/websocket/WebSocketStompIntegrationTest.java renamed to src/test/java/com/example/solidconnection/websocket/WebSocketHandshakeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
3131

3232
@TestContainerSpringBootTest
33-
@DisplayName("WebSocket/STOMP 통합 테스트")
34-
class WebSocketStompIntegrationTest {
33+
@DisplayName("WebSocket Handshake 테스트")
34+
class WebSocketHandshakeTest {
3535

3636
@LocalServerPort
3737
private int port;
@@ -47,7 +47,7 @@ class WebSocketStompIntegrationTest {
4747

4848
@BeforeEach
4949
void setUp() {
50-
this.url = String.format("ws://localhost:%d/connect", port);
50+
this.url = String.format("http://localhost:%d/connect", port);
5151
List<Transport> transports = List.of(new WebSocketTransport(new StandardWebSocketClient()));
5252
this.stompClient = new WebSocketStompClient(new SockJsClient(transports));
5353
this.stompClient.setMessageConverter(new MappingJackson2MessageConverter());

0 commit comments

Comments
 (0)