newtype
::: newtype의 지식창고 :::
newtype
전체 방문자
오늘
어제
  • 분류 전체보기 (392)
    • Dev (214)
      • C, C++ (43)
      • Go (5)
      • Web (49)
      • DBMS (21)
      • DevOps (8)
      • Java (2)
      • Windows, Win32 (4)
      • Visual Basic (5)
      • C# (2)
      • Mobile (25)
      • SQL CE (7)
      • Google Map (6)
      • Python (2)
      • cygwin (2)
      • 기타 (32)
      • Ruby (1)
    • 명언 (10)
    • 모임 (18)
      • 붕주회 (3)
      • 신흥컴정 (14)
      • 웹20기 (1)
    • 사진 (8)
    • 불펌 (29)
    • 막글 (98)
    • 게임 (6)
    • 여행 (8)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • 관리

공지사항

  • whoami
05-13 00:00
hELLO · Designed By 정상우.
newtype

::: newtype의 지식창고 :::

Dev/Web

websocket과 ssl 사용을 위한 nginx 설정

2023. 4. 25. 08:47

개인프로젝트로 간단한 멀티 테트리스를 만들고 있는데, https + websocket 조합이다 보니 서버 설정이 필요했습니다. 구글링을 통해 해결했고, 방법을 공유 합니다.

  1. html

html 파일에 메타 테그를 추가합니다.

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
  1. javascript

javascript에서 websocket을 연동을 위한 URI를 지정합니다.
( mydomain은 서비스할 도메인명을 넣어줍니다 )

ws = new WebSocket("ws://mydomain/ws");
  1. https

nginx 에 ssl 설정을 추가합니다.
mydomain/ws로 연결요청이 들어오면, 8090 포트의 /ws 로 포워딩합니다.

server {
    server_name  mydomain;
    listen 443 ssl;

    location /ws {
        proxy_pass   http://127.0.0.1:8090/ws;
        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-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
반응형
저작자표시

'Dev > Web' 카테고리의 다른 글

Nginx geoip 연동  (0) 2022.11.17
Nginx SSL 설정  (0) 2022.11.16
Code Finder  (0) 2017.05.25
FAQ html 템플릿  (0) 2015.08.28
카카오톡 그룹 채팅방 통계  (2) 2013.12.17
    'Dev/Web' 카테고리의 다른 글
    • Nginx geoip 연동
    • Nginx SSL 설정
    • Code Finder
    • FAQ html 템플릿
    newtype
    newtype
    지극히 개인적인 지식의 창고

    티스토리툴바