Skip to content

๐Ÿด nginx websocket ์—ฐ๊ฒฐ ์‹œ ๋ฌธ์ œ ๋ฐœ์ƒ

baegyeong edited this page Nov 29, 2024 · 1 revision
๋ถ„์•ผ ์ž‘์„ฑ์ž ์ž‘์„ฑ์ผ
BE ๊น€์„ฑํ™˜ 24๋…„ 11์›” 21์ผ

๋ฌธ์ œ ์‹œ์ž‘

  • ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ๋กœ์จ ์•ž์— nginx์„ ๋ถ™์—ฌ ์‚ฌ์šฉ์ค‘์— ์žˆ๋‹ค.
  • ๋ฌธ์ œ๋Š” websocket์„ ์—ฐ๊ฒฐํ•  ๋•Œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
  • ์—๋Ÿฌ ์ฝ”๋“œ์—์„œ๋Š” 301๊ฐ€ ๋œฌ๋‹ค.

๋ฌธ์ œ ์›์ธ ํŒŒ์•…

  • 301์€ ๋ฆฌ๋‹ค์ด๋ ‰์…˜์ด ๋˜๋Š” ๊ฒƒ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
  • ์šฐ๋ฆฌ๋Š” socket.io๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
    • ์ด๋•Œ, ์ฒ˜์Œ์— ์—”๋“œํฌ์ธํŠธ๊ฐ€ /socket.io๋กœ ๋“ค์–ด์˜ค๊ฒŒ ๋˜๋Š” ๋ฐ(postman ๊ธฐ๋ณธ ์„ค์ •)
    • socket.io๋Š” ์ฒ˜์Œ ์š”์ฒญ์„ ๋ณด๋‚ผ ๋•Œ http๋กœ ๋ณด๋‚ด๊ฒŒ ๋œ๋‹ค.
    • http๋Š” location /์ผ๋•Œ ๋ชจ๋“  ์š”์ฒญ์„ 301๋กœ ์‘๋‹ต, https๋กœ ์—…๊ทธ๋ ˆ์ด๋“œ๋œ ์ฃผ์†Œ๋ฅผ ๋ฆฌํ„ดํ•จ์œผ๋กœ์จ https๋กœ ์—…๊ทธ๋ ˆ์ด๋“œํ•˜๋Š” ๊ฒƒ์„ ์š”๊ตฌํ•œ๋‹ค.
    • ๋ฌธ์ œ๋Š” ์ด๊ฑธ socket.io๊ฐ€ ์ฒ˜์Œ ํ•ธ๋“œ์‰์ดํฌํ•  ๋•Œ์—๋Š” ์ œ๋Œ€๋กœ ์•Œ ์ˆ˜ ์—†๋‹ค๋Š” ๋ฌธ์ œ์ด๋‹ค.

๋ฌธ์ œ ํ•ด๊ฒฐ

  • reverse proxy์—์„œ ์‚ฌ์šฉํ•˜๋Š” nginx ์„ค์ •์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ฐ”๊ฟ”์ค˜์„œ ์ฒ˜์Œ ํ•ธ๋“œ์‰์ดํฌํ•  ๋•Œ์—๋Š” http๊ฐ€ ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋ฐ”๊ฟ”์คฌ๋‹ค.
  server {
      listen 80;
      server_name juchum.info;
      location /socket.io {
          proxy_pass         http://nest-api-server/socket.io;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
      }
      location / {
          return 301 https://$host$request_uri;
      }
      location /.well-known/acme-challenge/ {
          root /var/www/certbot;
      }
  }
  • ์ด์ œ๋Š” ์•„์ฃผ ์ž˜๋œ๋‹ค!

์ฐธ๊ณ  ์ž๋ฃŒ

https://velog.io/@penrose_15/Websocket-%EB%B0%8F-Websocket-%ED%85%8C%EC%8A%A4%ED%8A%B8

https://dev-gorany.tistory.com/330

๐Ÿœ ํŒ€ ๊ฐœ๋ฏธ

๐Ÿ›๏ธ ํŒ€ ๋ฌธํ™”

๊ฐœ๋ฐœ ์œ„ํ‚ค

FE

BE

Infra

๐Ÿ—ฃ๏ธ ๋ฐœํ‘œ

๐Ÿ“š ํšŒ์˜๋ก

๐Ÿ”ด ์ธํ„ฐ๋ฏธ์…˜
๐ŸŸ  1์ฃผ์ฐจ
๐ŸŸก 2์ฃผ์ฐจ
๐ŸŸข 3์ฃผ์ฐจ
๐Ÿ”ต 4์ฃผ์ฐจ
๐ŸŸฃ 5์ฃผ์ฐจ
๐ŸŸค 6์ฃผ์ฐจ

๐Ÿ’ญ ํšŒ๊ณ 

๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ ๋ฉ˜ํ† ๋ง

Clone this wiki locally