SlideShare une entreprise Scribd logo
1  sur  29
사설 인증서 적용(개발서버)
CentOS7
Intro
Kafka Cluster
incoming message
- without kafka client library support
(e.g. Android or IOS app, IOT devices, …)
- send message using Rest APIs
https
- 443 port : web page (for test)
- 8443 port : rest service
방화벽 개방(HTTPS)
• 443, 8443
[root@master ~]# firewall-cmd --permanent --zone=public --add-port=8443/tcp
success
[root@master ~]# firewall-cmd --permanent --zone=public --add-port=443/tcp
success
[root@master ~]# firewall-cmd --reload
success
[root@master ~]# firewall-cmd --list-all
사설 인증서 생성
[root@master ~]# mkdir /root/ssl/
[root@master ~]# cd ssl
[root@master ssl]# openssl req -x509 -days 358000 -nodes -newkey rsa:2048 
> -keyout /root/ssl/nginx-ssl.key -out /root/ssl/nginx-ssl.crt
Generating a 2048 bit RSA private key
........+++
.....................................................................................................+++
writing new private key to '/root/ssl/nginx-ssl.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:KR
State or Province Name (full name) []:Seoul
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:Kopo
Organizational Unit Name (eg, section) []:smart finance
Common Name (eg, your name or your server's hostname) []:devfmd
Email Address []:a@a.com
인증서 만료일 : 미지정시 30일, 테스트용으로 몇 백년 지정
openssl req -x509 -days 358000 -nodes -newkey rsa:2048 
-keyout /root/ssl/nginx-ssl.key -out /root/ssl/nginx-ssl.crt
도메인명 일치해야 함(불일치시 클라이언트에서 인증서 오류발생으로 접속 불가)
Nginx 디렉토리로 인증서 카피
인증서 복사를 mv가 아닌 cp명령으로 수행해야 하는 이유 : https://stackoverflow.com/questions/37994513/
Nginx 설정(443)
server {
listen 80;
#server_name localhost;
server_name devfmd;
return 301 https://$host$request_uri;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name devfmd;
root /usr/share/nginx/html;
ssl_certificate "/etc/nginx/nginx-ssl.crt";
ssl_certificate_key "/etc/nginx/nginx-ssl.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
/etc/nginx/conf.d/default.conf
host명 설정
서버에서 설정
로컬 PC에서 설정
Nginx 시작 및 브라우저 테스트
• systemctl start nginx
인증서 확인
결과 확인
• http://devfmd 접속시 https://devfmd로 자동 이동(301)
Nginx 설정(8443) /etc/nginx/conf.d/test.conf
server {
listen 8443 ssl http2;
listen [::]:8443 ssl http2;
server_name devfmd;
ssl_certificate "/etc/nginx/nginx-ssl.crt";
ssl_certificate_key "/etc/nginx/nginx-ssl.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /api {
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 3000;
proxy_pass http://testme/api;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
테스트 준비
• nginx -s reload
• 백엔드 어플리케이션 준비
포스트맨 준비
ssl 검증 옵션을 off 한다 : 제일 간편하나 권장하지 않음
포스트맨 테스트
포스트맨 준비(w/ 인증서)
• 사설 인증서 등록
• pem, crt, key를 등록
• pem은 기존 crt로부터 생성
• pfx는 기존 crt, key로부터 생성
https://learning.postman.com/docs/sending-requests/certificates/
https://www.tp-link.com/kr/support/faq/3330/
openssl x509 -in nginx-ssl.crt -out nginx-ssl.pem -outform PEM
openssl pkcs12 -export -in nginx-ssl.crt -inkey nginx-ssl.key -out nginx-ssl.pfx
포스트맨에 사설 인증서 등록
포스트맨에 사설 인증서 등록
서버에서 다운로드한 인증서 파일을 등록한다.
도메인명은 인증서 CN명과 같아야 함 서버에서 다운로드한 인증서 파일을 등록한다.
포스트맨에 사설 인증서 등록
등록 결과
테스트 결과
https 정상 통신 확인
[참고] curl https request
curl --location --request GET 'https://devfmd:8443/api' --header 'Content-Type: application/json'-v --cacert nginx-ssl.crt
정식 인증서 적용 (운영서버)
Ubuntu 18.04
사전 준비 사항 : 도메인, 고정IP
-> 없을 경우 ngrok 이용하여 설치
Nginx 설치
• apt-get install nginx
• {Nginx Home Directory}/sites-available/default
upstream testme {
server 127.0.0.1:8030;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
location @rewrites {
rewrite ^(.+)$ /index.html last;
}
location / {
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 3000;
proxy_pass http://testme;
}
}
default
Certbot 설치
• $ sudo apt-get update
• $ sudo apt-get install software-properties-common
• $ sudo add-apt-repository universe
• $ sudo add-apt-repository ppa:certbot/certbot
• $ sudo apt-get update
# 만약 다음과 같은 에러가 난다면?
E: The repository 'http://ppa.launchpad.net/certbot/certbot/ubuntu focal Release' does not have a Release file.
$ sudo apt-add-repository -r ppa:certbot/certbot
Certbot 인증서 발급(Let’s Encrpyt)
• certbot --nginx -d 도메인명
예>
certbot --nginx -d sort.example.net
• 발급 결과
root@ip-172-31-6-254:/etc/letsencrypt/live/sort.example.net# ll
total 12
drwxr-xr-x 2 root root 4096 Dec 10 16:25 ./
drwx------ 3 root root 4096 Dec 10 16:25 ../
-rw-r--r-- 1 root root 692 Dec 10 16:25 README
lrwxrwxrwx 1 root root 41 Dec 10 16:25 cert.pem -> ../../archive/sort.example.net/cert1.pem
lrwxrwxrwx 1 root root 42 Dec 10 16:25 chain.pem -> ../../archive/sort.example.net/chain1.pem
lrwxrwxrwx 1 root root 46 Dec 10 16:25 fullchain.pem -> ../../archive/sort.example.net/fullchain1.pem
lrwxrwxrwx 1 root root 44 Dec 10 16:25 privkey.pem -> ../../archive/sort.example.net/privkey1.pem
결과 확인
http 접속시 https 자동 이동
certobot 인증서 발급시 nginx default 파일에
https 관련 코드와 301 리다이렉션 코드
자동으로 추가됨
Certbot 인증서 자동갱신 크론탭 등록
• certbot renew --dry-run
• /etc/cron.d/에 크론탭 자동 등록
고정IP, 도메인이 없는 경우
• ngrok 또는 localtunnel 적용 고려(임시방편)
ngrok : 하나의 서버에 대해 무료, 서버 재시작시 도메인 변경됨
localtunnel : 도메인명.loca.lt 형태로 고정되나, 중계서버 간헐적 불안정
VS
https://localtunnel.github.io/www/
https://ngrok.com/
참고자료
• CentOS에서 Nginx, Certbot 설치하고 인증서 적용하기
https://stove99.github.io/linux/2019/08/27/install-lets-encrypt-to-nginx-in-centos/
• Root CA 인증서 발급 및 적용 절차
https://www.sslcert.co.kr/guides/NGINX-SSL-Certificate-Install
https://velog.io/@twkim8548/Nginx%EC%97%90%EC%84%9C-SSL-%EC%A0%81%EC%9A%A9%ED%95%B4%EC%84%9C-Https-%EB%A1%9C-
%EC%A0%91%EC%86%8D-%EB%90%98%EA%B2%8C-%ED%95%B4%EB%B3%BC%EA%B9%8C

Contenu connexe

Similaire à Nginx Https 적용하기.pptx

Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11Dongil Yeom
 
nexus helm 설치, docker/helm repo 설정과 예제
nexus helm 설치, docker/helm repo 설정과 예제nexus helm 설치, docker/helm repo 설정과 예제
nexus helm 설치, docker/helm repo 설정과 예제choi sungwook
 
[오픈소스컨설팅] Atlassian webinar 기본 트러블슈팅(1 of 2)
[오픈소스컨설팅] Atlassian webinar 기본 트러블슈팅(1 of 2)[오픈소스컨설팅] Atlassian webinar 기본 트러블슈팅(1 of 2)
[오픈소스컨설팅] Atlassian webinar 기본 트러블슈팅(1 of 2)Osc Osc
 
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기흥배 최
 
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 Docker
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 DockerXECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 Docker
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 DockerXpressEngine
 
프로젝트용 PC 환경구성 이찬희
프로젝트용 PC 환경구성   이찬희프로젝트용 PC 환경구성   이찬희
프로젝트용 PC 환경구성 이찬희찬희 이
 
20141229 dklee docker
20141229 dklee docker20141229 dklee docker
20141229 dklee dockerDK Lee
 
Kafka monitoring using Prometheus and Grafana
Kafka monitoring using Prometheus and GrafanaKafka monitoring using Prometheus and Grafana
Kafka monitoring using Prometheus and Grafanawonyong hwang
 
리눅스서버세팅-김태호
리눅스서버세팅-김태호리눅스서버세팅-김태호
리눅스서버세팅-김태호ETRIBE_STG
 
20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제Tae Young Lee
 
Mininet
MininetMininet
Mininetymtech
 
[Ansible] Solution Guide V0.4_20181204.pdf
[Ansible] Solution Guide V0.4_20181204.pdf[Ansible] Solution Guide V0.4_20181204.pdf
[Ansible] Solution Guide V0.4_20181204.pdfHeeJung Chae
 
11_웹서비스활용
11_웹서비스활용11_웹서비스활용
11_웹서비스활용noerror
 
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기Ted Won
 
Actual PoC guide for Virtual Desktop Infrastructure (Korean)
Actual PoC guide for Virtual Desktop Infrastructure (Korean)Actual PoC guide for Virtual Desktop Infrastructure (Korean)
Actual PoC guide for Virtual Desktop Infrastructure (Korean)Changhyun Lim
 
Hyperledger fabric practice(pdf)
Hyperledger fabric practice(pdf)Hyperledger fabric practice(pdf)
Hyperledger fabric practice(pdf)wonyong hwang
 
Puppet과 자동화된 시스템 관리
Puppet과 자동화된 시스템 관리Puppet과 자동화된 시스템 관리
Puppet과 자동화된 시스템 관리Keon Ahn
 
PCF Installation Guide
PCF Installation GuidePCF Installation Guide
PCF Installation Guideseungdon Choi
 

Similaire à Nginx Https 적용하기.pptx (20)

HTTPS, 원격제어
HTTPS, 원격제어HTTPS, 원격제어
HTTPS, 원격제어
 
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
Udamp3 django apache-my_sql_python3_ubuntu14.04-v11
 
nexus helm 설치, docker/helm repo 설정과 예제
nexus helm 설치, docker/helm repo 설정과 예제nexus helm 설치, docker/helm repo 설정과 예제
nexus helm 설치, docker/helm repo 설정과 예제
 
[오픈소스컨설팅] Atlassian webinar 기본 트러블슈팅(1 of 2)
[오픈소스컨설팅] Atlassian webinar 기본 트러블슈팅(1 of 2)[오픈소스컨설팅] Atlassian webinar 기본 트러블슈팅(1 of 2)
[오픈소스컨설팅] Atlassian webinar 기본 트러블슈팅(1 of 2)
 
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
 
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 Docker
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 DockerXECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 Docker
XECon2015 :: [1-5] 김훈민 - 서버 운영자가 꼭 알아야 할 Docker
 
프로젝트용 PC 환경구성 이찬희
프로젝트용 PC 환경구성   이찬희프로젝트용 PC 환경구성   이찬희
프로젝트용 PC 환경구성 이찬희
 
20141229 dklee docker
20141229 dklee docker20141229 dklee docker
20141229 dklee docker
 
Kafka monitoring using Prometheus and Grafana
Kafka monitoring using Prometheus and GrafanaKafka monitoring using Prometheus and Grafana
Kafka monitoring using Prometheus and Grafana
 
OpenStack Swift Debugging
OpenStack Swift DebuggingOpenStack Swift Debugging
OpenStack Swift Debugging
 
리눅스서버세팅-김태호
리눅스서버세팅-김태호리눅스서버세팅-김태호
리눅스서버세팅-김태호
 
20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제20141029 하둡2.5와 hive설치 및 예제
20141029 하둡2.5와 hive설치 및 예제
 
Mininet
MininetMininet
Mininet
 
[Ansible] Solution Guide V0.4_20181204.pdf
[Ansible] Solution Guide V0.4_20181204.pdf[Ansible] Solution Guide V0.4_20181204.pdf
[Ansible] Solution Guide V0.4_20181204.pdf
 
11_웹서비스활용
11_웹서비스활용11_웹서비스활용
11_웹서비스활용
 
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기
JCO 11th 클라우드 환경에서 Java EE 운영 환경 구축하기
 
Actual PoC guide for Virtual Desktop Infrastructure (Korean)
Actual PoC guide for Virtual Desktop Infrastructure (Korean)Actual PoC guide for Virtual Desktop Infrastructure (Korean)
Actual PoC guide for Virtual Desktop Infrastructure (Korean)
 
Hyperledger fabric practice(pdf)
Hyperledger fabric practice(pdf)Hyperledger fabric practice(pdf)
Hyperledger fabric practice(pdf)
 
Puppet과 자동화된 시스템 관리
Puppet과 자동화된 시스템 관리Puppet과 자동화된 시스템 관리
Puppet과 자동화된 시스템 관리
 
PCF Installation Guide
PCF Installation GuidePCF Installation Guide
PCF Installation Guide
 

Plus de wonyong hwang

Hyperledger Explorer.pptx
Hyperledger Explorer.pptxHyperledger Explorer.pptx
Hyperledger Explorer.pptxwonyong hwang
 
하이퍼레저 페이지 단위 블록 조회
하이퍼레저 페이지 단위 블록 조회하이퍼레저 페이지 단위 블록 조회
하이퍼레저 페이지 단위 블록 조회wonyong hwang
 
토큰 증권 개요.pptx
토큰 증권 개요.pptx토큰 증권 개요.pptx
토큰 증권 개요.pptxwonyong hwang
 
Vue.js 기초 실습.pptx
Vue.js 기초 실습.pptxVue.js 기초 실습.pptx
Vue.js 기초 실습.pptxwonyong hwang
 
Deploying Hyperledger Fabric on Kubernetes.pptx
Deploying Hyperledger Fabric on Kubernetes.pptxDeploying Hyperledger Fabric on Kubernetes.pptx
Deploying Hyperledger Fabric on Kubernetes.pptxwonyong hwang
 
k8s practice 2023.pptx
k8s practice 2023.pptxk8s practice 2023.pptx
k8s practice 2023.pptxwonyong hwang
 
HyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdfHyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdfwonyong hwang
 
Kafka JDBC Connect Guide(Postgres Sink).pptx
Kafka JDBC Connect Guide(Postgres Sink).pptxKafka JDBC Connect Guide(Postgres Sink).pptx
Kafka JDBC Connect Guide(Postgres Sink).pptxwonyong hwang
 
Nginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptxNginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptxwonyong hwang
 
주가 정보 다루기.pdf
주가 정보 다루기.pdf주가 정보 다루기.pdf
주가 정보 다루기.pdfwonyong hwang
 
App development with quasar (pdf)
App development with quasar (pdf)App development with quasar (pdf)
App development with quasar (pdf)wonyong hwang
 
Hyperledger Fabric practice (v2.0)
Hyperledger Fabric practice (v2.0) Hyperledger Fabric practice (v2.0)
Hyperledger Fabric practice (v2.0) wonyong hwang
 
Hyperledger composer
Hyperledger composerHyperledger composer
Hyperledger composerwonyong hwang
 
BlockChain implementation by python
BlockChain implementation by pythonBlockChain implementation by python
BlockChain implementation by pythonwonyong hwang
 
Block chain introduction slideshare
Block chain introduction   slideshareBlock chain introduction   slideshare
Block chain introduction slidesharewonyong hwang
 

Plus de wonyong hwang (19)

Hyperledger Explorer.pptx
Hyperledger Explorer.pptxHyperledger Explorer.pptx
Hyperledger Explorer.pptx
 
하이퍼레저 페이지 단위 블록 조회
하이퍼레저 페이지 단위 블록 조회하이퍼레저 페이지 단위 블록 조회
하이퍼레저 페이지 단위 블록 조회
 
토큰 증권 개요.pptx
토큰 증권 개요.pptx토큰 증권 개요.pptx
토큰 증권 개요.pptx
 
Vue.js 기초 실습.pptx
Vue.js 기초 실습.pptxVue.js 기초 실습.pptx
Vue.js 기초 실습.pptx
 
Deploying Hyperledger Fabric on Kubernetes.pptx
Deploying Hyperledger Fabric on Kubernetes.pptxDeploying Hyperledger Fabric on Kubernetes.pptx
Deploying Hyperledger Fabric on Kubernetes.pptx
 
k8s practice 2023.pptx
k8s practice 2023.pptxk8s practice 2023.pptx
k8s practice 2023.pptx
 
HyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdfHyperLedger Fabric V2.5.pdf
HyperLedger Fabric V2.5.pdf
 
Kafka JDBC Connect Guide(Postgres Sink).pptx
Kafka JDBC Connect Guide(Postgres Sink).pptxKafka JDBC Connect Guide(Postgres Sink).pptx
Kafka JDBC Connect Guide(Postgres Sink).pptx
 
Nginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptxNginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptx
 
Kafka Rest.pptx
Kafka Rest.pptxKafka Rest.pptx
Kafka Rest.pptx
 
주가 정보 다루기.pdf
주가 정보 다루기.pdf주가 정보 다루기.pdf
주가 정보 다루기.pdf
 
KAFKA 3.1.0.pdf
KAFKA 3.1.0.pdfKAFKA 3.1.0.pdf
KAFKA 3.1.0.pdf
 
App development with quasar (pdf)
App development with quasar (pdf)App development with quasar (pdf)
App development with quasar (pdf)
 
kubernetes practice
kubernetes practicekubernetes practice
kubernetes practice
 
Hyperledger Fabric practice (v2.0)
Hyperledger Fabric practice (v2.0) Hyperledger Fabric practice (v2.0)
Hyperledger Fabric practice (v2.0)
 
Docker practice
Docker practiceDocker practice
Docker practice
 
Hyperledger composer
Hyperledger composerHyperledger composer
Hyperledger composer
 
BlockChain implementation by python
BlockChain implementation by pythonBlockChain implementation by python
BlockChain implementation by python
 
Block chain introduction slideshare
Block chain introduction   slideshareBlock chain introduction   slideshare
Block chain introduction slideshare
 

Nginx Https 적용하기.pptx

  • 1.
  • 3. Intro Kafka Cluster incoming message - without kafka client library support (e.g. Android or IOS app, IOT devices, …) - send message using Rest APIs https - 443 port : web page (for test) - 8443 port : rest service
  • 4. 방화벽 개방(HTTPS) • 443, 8443 [root@master ~]# firewall-cmd --permanent --zone=public --add-port=8443/tcp success [root@master ~]# firewall-cmd --permanent --zone=public --add-port=443/tcp success [root@master ~]# firewall-cmd --reload success [root@master ~]# firewall-cmd --list-all
  • 5. 사설 인증서 생성 [root@master ~]# mkdir /root/ssl/ [root@master ~]# cd ssl [root@master ssl]# openssl req -x509 -days 358000 -nodes -newkey rsa:2048 > -keyout /root/ssl/nginx-ssl.key -out /root/ssl/nginx-ssl.crt Generating a 2048 bit RSA private key ........+++ .....................................................................................................+++ writing new private key to '/root/ssl/nginx-ssl.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:KR State or Province Name (full name) []:Seoul Locality Name (eg, city) [Default City]: Organization Name (eg, company) [Default Company Ltd]:Kopo Organizational Unit Name (eg, section) []:smart finance Common Name (eg, your name or your server's hostname) []:devfmd Email Address []:a@a.com 인증서 만료일 : 미지정시 30일, 테스트용으로 몇 백년 지정 openssl req -x509 -days 358000 -nodes -newkey rsa:2048 -keyout /root/ssl/nginx-ssl.key -out /root/ssl/nginx-ssl.crt 도메인명 일치해야 함(불일치시 클라이언트에서 인증서 오류발생으로 접속 불가)
  • 6. Nginx 디렉토리로 인증서 카피 인증서 복사를 mv가 아닌 cp명령으로 수행해야 하는 이유 : https://stackoverflow.com/questions/37994513/
  • 7. Nginx 설정(443) server { listen 80; #server_name localhost; server_name devfmd; return 301 https://$host$request_uri; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name devfmd; root /usr/share/nginx/html; ssl_certificate "/etc/nginx/nginx-ssl.crt"; ssl_certificate_key "/etc/nginx/nginx-ssl.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } /etc/nginx/conf.d/default.conf
  • 9. Nginx 시작 및 브라우저 테스트 • systemctl start nginx
  • 11. 결과 확인 • http://devfmd 접속시 https://devfmd로 자동 이동(301)
  • 12. Nginx 설정(8443) /etc/nginx/conf.d/test.conf server { listen 8443 ssl http2; listen [::]:8443 ssl http2; server_name devfmd; ssl_certificate "/etc/nginx/nginx-ssl.crt"; ssl_certificate_key "/etc/nginx/nginx-ssl.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location /api { proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; send_timeout 3000; proxy_pass http://testme/api; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
  • 13. 테스트 준비 • nginx -s reload • 백엔드 어플리케이션 준비
  • 14. 포스트맨 준비 ssl 검증 옵션을 off 한다 : 제일 간편하나 권장하지 않음
  • 16. 포스트맨 준비(w/ 인증서) • 사설 인증서 등록 • pem, crt, key를 등록 • pem은 기존 crt로부터 생성 • pfx는 기존 crt, key로부터 생성 https://learning.postman.com/docs/sending-requests/certificates/ https://www.tp-link.com/kr/support/faq/3330/ openssl x509 -in nginx-ssl.crt -out nginx-ssl.pem -outform PEM openssl pkcs12 -export -in nginx-ssl.crt -inkey nginx-ssl.key -out nginx-ssl.pfx
  • 18. 포스트맨에 사설 인증서 등록 서버에서 다운로드한 인증서 파일을 등록한다. 도메인명은 인증서 CN명과 같아야 함 서버에서 다운로드한 인증서 파일을 등록한다.
  • 19. 포스트맨에 사설 인증서 등록 등록 결과
  • 21. [참고] curl https request curl --location --request GET 'https://devfmd:8443/api' --header 'Content-Type: application/json'-v --cacert nginx-ssl.crt
  • 22. 정식 인증서 적용 (운영서버) Ubuntu 18.04 사전 준비 사항 : 도메인, 고정IP -> 없을 경우 ngrok 이용하여 설치
  • 23. Nginx 설치 • apt-get install nginx • {Nginx Home Directory}/sites-available/default upstream testme { server 127.0.0.1:8030; } server { listen 80 default_server; listen [::]:80 default_server; location @rewrites { rewrite ^(.+)$ /index.html last; } location / { proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; send_timeout 3000; proxy_pass http://testme; } } default
  • 24. Certbot 설치 • $ sudo apt-get update • $ sudo apt-get install software-properties-common • $ sudo add-apt-repository universe • $ sudo add-apt-repository ppa:certbot/certbot • $ sudo apt-get update # 만약 다음과 같은 에러가 난다면? E: The repository 'http://ppa.launchpad.net/certbot/certbot/ubuntu focal Release' does not have a Release file. $ sudo apt-add-repository -r ppa:certbot/certbot
  • 25. Certbot 인증서 발급(Let’s Encrpyt) • certbot --nginx -d 도메인명 예> certbot --nginx -d sort.example.net • 발급 결과 root@ip-172-31-6-254:/etc/letsencrypt/live/sort.example.net# ll total 12 drwxr-xr-x 2 root root 4096 Dec 10 16:25 ./ drwx------ 3 root root 4096 Dec 10 16:25 ../ -rw-r--r-- 1 root root 692 Dec 10 16:25 README lrwxrwxrwx 1 root root 41 Dec 10 16:25 cert.pem -> ../../archive/sort.example.net/cert1.pem lrwxrwxrwx 1 root root 42 Dec 10 16:25 chain.pem -> ../../archive/sort.example.net/chain1.pem lrwxrwxrwx 1 root root 46 Dec 10 16:25 fullchain.pem -> ../../archive/sort.example.net/fullchain1.pem lrwxrwxrwx 1 root root 44 Dec 10 16:25 privkey.pem -> ../../archive/sort.example.net/privkey1.pem
  • 26. 결과 확인 http 접속시 https 자동 이동 certobot 인증서 발급시 nginx default 파일에 https 관련 코드와 301 리다이렉션 코드 자동으로 추가됨
  • 27. Certbot 인증서 자동갱신 크론탭 등록 • certbot renew --dry-run • /etc/cron.d/에 크론탭 자동 등록
  • 28. 고정IP, 도메인이 없는 경우 • ngrok 또는 localtunnel 적용 고려(임시방편) ngrok : 하나의 서버에 대해 무료, 서버 재시작시 도메인 변경됨 localtunnel : 도메인명.loca.lt 형태로 고정되나, 중계서버 간헐적 불안정 VS https://localtunnel.github.io/www/ https://ngrok.com/
  • 29. 참고자료 • CentOS에서 Nginx, Certbot 설치하고 인증서 적용하기 https://stove99.github.io/linux/2019/08/27/install-lets-encrypt-to-nginx-in-centos/ • Root CA 인증서 발급 및 적용 절차 https://www.sslcert.co.kr/guides/NGINX-SSL-Certificate-Install https://velog.io/@twkim8548/Nginx%EC%97%90%EC%84%9C-SSL-%EC%A0%81%EC%9A%A9%ED%95%B4%EC%84%9C-Https-%EB%A1%9C- %EC%A0%91%EC%86%8D-%EB%90%98%EA%B2%8C-%ED%95%B4%EB%B3%BC%EA%B9%8C

Notes de l'éditeur

  1. 인증서 만료는 디폴트 30일 : https://serverfault.com/questions/920461/why-openssl-ignore-days-for-expiration-date-for-self-signed-certificate
  2. openssl pkcs12 -export -in nginx-ssl.crt -inkey nginx-ssl.key -out nginx-ssl.pfx Enter Export Password: Verifying - Enter Export Password:
  3. curl --location --request GET 'https://devfmd:8443/api' --header 'Content-Type: application/json'-v --cacert nginx-ssl.crt
  4. 필요시 {nginx home directory}/nginx.conf에서 user root; 설정
  5. https://jamie95.tistory.com/184
  6. /etc/nginx/sites-available/default 파일 하단에서 301 리다이렉션 부분 주석처리 후, if문만 상단 80 섹션으로 이동시킨다. (이렇게 하면 80 을 443 으로 이동시키면서 http를 사용하는 다른 서비스 유지 가능) server { listen 80 default_server; listen [::]:80 default_server; if ($host = smart.wonyong.net) { return 301 https://$host$request_uri; }
  7. https://kibua20.tistory.com/151