Nginx SSL 인증서 설치[CentOS 7]

Nginx SSL 인증서 설치를 진행합니다.

1. 인증서 신청하기

SSL 인증서는 30일 무료 SSL을 https://zerossl.com/ 사이트에서 신청했습니다.

Nginx SSL 설치-Free 30일 신청 1
Nginx SSL 설치-Free 30일 신청 2
Nginx SSL 설치-Free 30일 신청 3

DCV 인증은 DNS 인증 방식으로 진행했습니다.

Nginx SSL 설치-Free 30일 신청 4_DEV DNS 인증

네임서버에서 CNAME 레코드를 설정합니다.

Nginx SSL 설치-Free 30일 신청 4_DEV DNS 인증2

설정 후 인증 신청을 한 후 대기 시간이 소요됩니다.

Nginx SSL 설치-Free 30일 신청 5

인증이 완료되면 인증서 파일을 다운로드 받은 후 서버에 인증서 설치 작업을 진행합니다.

Nginx SSL 설치-Free 30일 신청 6

2. 방화벽 설정

윈도우 처음 설치 후 특별한 설정을 하지 않았다면 기본 방화벽은 firewallD 데몬입니다.

firewall-cmd --permanent --add-service=https
firewall-cmd --reload

3. ssl 인증서 업로드

lrzsz 툴을 설치 후 드래그 하여 파일을 업로드 합니다.

cd /etc/nginx/
mkdir ssl
yum -y install lrzsz

4. user.conf SSL 적용

기존 80번 포트의 서버 블록에서 추가로 443 포트의 SSL 적용할 서버 블록을 만들어서 SSL 인증서 적용할 내용을 추가합니다.

# http 서버 블록
server {
    listen       80;
    server_name  mydomain.com;
    #http로 접속할 경우 https로 리다이렉트
    return 301 https://$host$request_uri;
    location / {
        root   /home/testuser/www;
        index  index.html index.htm index.php;
        charset utf-8;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        root           /home/testuser/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

# HTTPS 서버 블록 설정 추가
server {
    listen       443 ssl;
    server_name  mydomain.com;

    ssl_certificate     /etc/nginx/ssl/certificate.crt;
    ssl_certificate_key /etc/nginx/ssl/private.key;

    root   /home/testuser/www;
    index  index.html index.htm index.php;
    charset utf-8;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        root           /home/testuser/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
Nginx 서버 블록
├── HTTP 서버 블록 (포트 80)
   ├── server_name: localhost; or domain(mydomain.com)
   ├── 리다이렉트: http  https (return 301 https://$host$request_uri)
   ├── location /
      ├── root: /home/testuser/www
      ├── index: index.html, index.htm, index.php
      └── charset: utf-8
   ├── location = /50x.html
      └── root: /usr/share/nginx/html
   └── location ~ \.php$
       ├── root: /home/testuser/www
       ├── fastcgi_pass: 127.0.0.1:9000
       ├── fastcgi_index: index.php
       ├── fastcgi_param: SCRIPT_FILENAME = $document_root$fastcgi_script_name
       └── include: fastcgi_params

├── HTTPS 서버 블록 (포트 443 ssl)
    ├── server_name: localhost; or domain(mydomain.com)
    ├── ssl_certificate: /etc/nginx/ssl/certificate.crt
    ├── ssl_certificate_key: /etc/nginx/ssl/private.key
    ├── root: /home/testuser/www
    ├── index: index.html, index.htm, index.php
    ├── charset: utf-8
    ├── location /
       └── try_files: $uri $uri/ =404
    ├── location ~ \.php$
       ├── root: /home/testuser/www
       ├── fastcgi_pass: 127.0.0.1:9000
       ├── fastcgi_index: index.php
       ├── fastcgi_param: SCRIPT_FILENAME = $document_root$fastcgi_script_name
       └── include: fastcgi_params
    └── location = /50x.html
        └── root: /usr/share/nginx/html

5. Nginx 재시작 및 SSL 인증서 적용 사항 확인

nginx -s reload

Nginx SSL 인증서가 정상적으로 설치 되었습니다.

Nginx SSL 설치 웹에서 확인하기

Similar Posts

  • 리눅스 netstat 명령어, ifconfig 명령어

    리눅스에 netstat 명령어 및 ifconfig 명령어를 실행하기 위해 리눅스 서버에 명령어 실행을 위한 net-tools이 설치되어 있어야 합니다. 목차1. 인증서 신청하기2. 방화벽 설정3. ssl 인증서 업로드4. user.conf SSL 적용5. Nginx 재시작 및 SSL 인증서 적용 사항 확인✅ net-tools 설치 ✅ netstat 명령어 netstat[network statistics:네트워크 통계]은 네트워크 상태를 확인하는 명령어입니다. 어떤 포트가 열려있고, 어떻게 사용되고…

  • 리눅스: useradd 명령어 & passwd 명령어

    useradd 명령어는 리눅스에서 사용자의 ID(계정)를 생성하는 명령어입니다. root 권한으로 생성이 가능하며 기본적인 명령은 아래와 같습니다. 목차1. 인증서 신청하기2. 방화벽 설정3. ssl 인증서 업로드4. user.conf SSL 적용5. Nginx 재시작 및 SSL 인증서 적용 사항 확인리눅스 useradd 명령어 옵션 리눅스 useradd 사용 예 기본으로 사용할 수 있는 예입니다. 리눅스 /etc/skel 디렉토리 계정 생성 시 설정…

  • 리눅스 touch 명령어

    touch 명령어는 파일의 날짜 시간 정보를 변경하는 명령어입니다. 아무 옵션 없이 사용할 경우 파일의 최근 사용 시간, 변경 시간이 서버의 현재 시간으로 변경됩니다. 파일이 없는 파일명을 입력할 경우 새로운 크기가 0인 빈 파일이 생성됩니다. 목차1. 인증서 신청하기2. 방화벽 설정3. ssl 인증서 업로드4. user.conf SSL 적용5. Nginx 재시작 및 SSL 인증서 적용 사항 확인✅…

  • 서블릿(Servlet)이란?

    목차1. 인증서 신청하기2. 방화벽 설정3. ssl 인증서 업로드4. user.conf SSL 적용5. Nginx 재시작 및 SSL 인증서 적용 사항 확인 1. 서블릿이란 무엇인가? 서블릿은 동적 웹 페이지를 만들 때 사용되는 자바 기반의 웹 애플리케이션 프로그래밍 기술입니다. 클라이언트의 요청을 처리하고 응답을 생성하는 자바 클래스입니다. Servlet은 일반적으로 HTTP 프로토콜을 기반으로 작동하며, 클라이언트의 요청을 받아들여 처리하고, 데이터베이스…

  • 스왑 메모리(Swap Memory) 설정: 파티션&파일 2가지 방식 | swapon, mkswap 명령어

    리눅스 스왑 메모리(Swap Memory)는 실제 디스크 공간을 메모리처럼 사용하는 개념이기 때문에 물리 메모리인 RAM보다 처리 속도가 느리지만 물리 메모리가 가득 찬 경우를 대비해 디스크 공간에서 할당 된 스왑 메모리를 생성해서 관리할 수 있어 한정된 리소스를 효율적으로 사용할 수 있습니다. 목차1. 인증서 신청하기2. 방화벽 설정3. ssl 인증서 업로드4. user.conf SSL 적용5. Nginx 재시작 및…

  • [Linux] CentOS 7 yum repo 변경(EOS)

    CentOS 7의 공식 EOS 날짜는 2024년 6월 30일로 종료되면서 기본 저장소가 비활성화되었기 때문에, yum 명령어 실행 시 저장소를 찾지 못해 오류가 발생합니다. CentOS 7 yum repo 변경을 한 후에 문제 해결이 가능합니다. CentOS 7에서 EOS(End of Support)에 따라 CentOS 7을 처음 설치 시 설정 된 yum 명령어 실행 시 One of the configured…

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

Prove your humanity: 6   +   4   =