Nginx SSL 인증서 설치[CentOS 7]
Nginx SSL 인증서 설치를 진행합니다.
1. 인증서 신청하기
SSL 인증서는 30일 무료 SSL을 https://zerossl.com/ 사이트에서 신청했습니다.
DCV 인증은 DNS 인증 방식으로 진행했습니다.
네임서버에서 CNAME 레코드를 설정합니다.
설정 후 인증 신청을 한 후 대기 시간이 소요됩니다.
인증이 완료되면 인증서 파일을 다운로드 받은 후 서버에 인증서 설치 작업을 진행합니다.
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 인증서가 정상적으로 설치 되었습니다.