newtype
::: newtype의 지식창고 :::
newtype
전체 방문자
608,034
오늘
2
어제
41
  • 분류 전체보기 (391)
    • it (213)
      • c (43)
      • VB (5)
      • csharp (2)
      • java (2)
      • etc (32)
      • www (49)
      • emb (25)
      • win (4)
      • db (20)
      • sqlce (7)
      • devOps (8)
      • gmap (6)
      • python (2)
      • cygwin (2)
      • go (5)
      • ruby (1)
    • 명언 (10)
    • 모임 (18)
      • 붕주회 (3)
      • 신흥컴정 (14)
      • 웹20기 (1)
    • 사진 (8)
    • 불펌 (29)
    • 막글 (98)
    • 게임 (6)
    • 여행 (8)

블로그 메뉴

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

공지사항

  • whoami
06-08 05:50
hELLO · Designed By 정상우.
newtype

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

it/www

Nginx SSL 설정

2022. 11. 16. 09:41

개인 프로젝트 공간을 Lightsail로 옮기면서 Apache에서 Nginx로 변경했습니다. 옮기고 나니 저사양에서는 Nginx가 훨씬 좋았습니다. 설정도 간단하고, 성능도 좋아졌네요.
Nginx에서 SSL 설정 방법을 설명합니다.

개인 환경

  • static html 페이지 몇 개가 노출 되야 합니다.
  • node.js로 8080 포트로 서비스가 올라갑니다.
  • grafana가 3000 포트로 올라갑니다.

SSL 기본 설정

server_name에 도메인을 넣고, static html 노출을 위해 web root 경로를 지정합니다.
키 파일을 지정하고, favicon 관련 불필요한 설정 off 했습니다.

server {
    server_name  mydomain.com;
    listen 443 ssl;

    location / {
        root   /home/bitnami/www;
        index  index.html index.htm;
    }

    ssl_certificate /home/bitnami/letsencrypt/certificates/mydomain.com.crt;
    ssl_certificate_key /home/bitnami/letsencrypt/certificates/mydomain.com.key;

    location = /favicon.ico {
        return 204;
        access_log     off;
        log_not_found  off;
    }
}

WebSocket 가상 호스트

node 8080 서비스는 추가로 서브 도메인 인증서를 발급받아 가상 호스트로 연결 했습니다.

websocket을 사용하는데, WebSocket connection to 'wss://node.mydomain.com/socket.io/?EIO=4&transport=websocket&sid=zn6gwaXKvWzDK35JAAA6' failed: 에러가 발생 합니다.
이를 해결하기 위해, proxy_http_version, proxy_set_header 설정을 몇 가지 추가합니다.

server {
    server_name  node.mydomain.com;
    listen 443 ssl;

    location / {
        proxy_pass   http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }


    ssl_certificate /home/bitnami/letsencrypt/certificates/node.mydomain.com.crt;
    ssl_certificate_key /home/bitnami/letsencrypt/certificates/node.mydomain.com.key;
}

Grafana 가상 호스트

grafana를 docker-compose로 설치해서 사용중인데, datasource PostgreSQL Connection 설정시 origin not allowed 에러가 발생합니다.
이를 해결하기 위해, proxy_set_header 설정을 몇 가지 추가합니다.

server {
    server_name  teslamate.mydomain.com;
    listen 443 ssl;

    location / {
        proxy_pass   http://127.0.0.1:3000;
        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;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    ssl_certificate /home/bitnami/letsencrypt/certificates/teslamate.mydomain.com.crt;
    ssl_certificate_key /home/bitnami/letsencrypt/certificates/teslamate.mydomain.com.key;
}
반응형
저작자표시
    'it/www' 카테고리의 다른 글
    • websocket과 ssl 사용을 위한 nginx 설정
    • Nginx geoip 연동
    • Code Finder
    • FAQ html 템플릿
    grafana, nginx, nodejs, ssl, teslamate, vhost, 가상호스트
    newtype
    newtype
    지극히 개인적인 지식의 창고
    댓글쓰기
    Nginx geoip 연동
    다음 글
    Nginx geoip 연동
    이전 글
    Code Finder

    티스토리툴바