Nginx 여러 HTTPS 도 메 인 설정
최근 에 위 챗 애플 릿 을 하고 있 습 니 다. 수중 에 있 습 니 다.
Nginx 는 TLS 프로 토 콜 의 SNI 확장 을 지원 합 니 다 (같은 IP 에 여러 개의 서로 다른 인증서 의 도 메 인 이름 을 지원 할 수 있 음). Nginx 를 다시 설치 해서 TLS 를 지원 하면 됩 니 다.
Nginx 설치
[root]# wget http://nginx.org/download/nginx-1.12.0.tar.gz
[root]# tar zxvf nginx-1.12.0.tar.gz
[root]# cd nginx-1.12.0
[root]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module \
--with-openssl=./openssl-1.0.1e \
--with-openssl-opt="enable-tlsext"
비고: 설치 과정 에서 클 라 우 드 서버 의 환경 에 라 이브 러 리 가 부족 한 것 을 발 견 했 습 니 다. 다운로드 한 후에 Nginx 의
./configure
명령 을 다시 실행 합 니 다. 구체 적 인 조작 은 다음 과 같 습 니 다.[root]# wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
[root]# tar zxvf pcre-8.35
[root]# yum -y install gcc
[root]# yum -y install gcc-c++
[root]# yum install -y zlib-devel
[root]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module \
--with-openssl=./openssl-1.0.1e \
--with-openssl-opt="enable-tlsext" \
--with-pcre=./pcre-8.35
Nginx 설정
도 메 인 이름 을 구 매 할 때 도 메 인 이름 공급 자가 무료 SSL 인증 서 를 가지 고 있 으 면 직접 사용 합 니 다.없 으 면 Let 's Encrist 를 사용 하여 무료 CA 인증 서 를 만 들 수 있 습 니 다.
Nginx 설정 열기:
vi /etc/nginx/nginx.conf
...
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name abc.com;
root /usr/share/nginx/html;
ssl_certificate "/root/keys/abc.com.pem";
ssl_certificate_key "/root/keys/abc.com.private.pem";
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name def.com;
root /usr/share/nginx/html;
ssl_certificate "/root/keys/def.com.pem";
ssl_certificate_key "/root/keys/def.com.private.pem";
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
설정 완료 후 Ngixn:
nginx -s reload
다시 불 러 오기무료 CA 인증서 신청
SSL 인증서 가 없 는 경우 아래 방법 으로 CA 인증서 인 Let 's Encript 를 무료 로 받 을 수 있 습 니 다.
단계 1: Let 's Encrypt 공식 클 라 이언 트 인 CetBot 설치
[root]# yum install -y epel-releasesudo
[root]# yum install -y certbot
단계 2: Nginx 프로필 을 설정 하고 서버 모듈 (80 포트 감청) 에 아래 설정 을 추가 합 니 다.
CertBot 은 서버 도 메 인 이름 을 검증 할 때 무 작위 파일 을 생 성 합 니 다. 그리고 CertBot 서버 는 HTTP 를 통 해 이 파일 에 접근 할 수 있 도록 Nginx 설정 을 확보 해 야 합 니 다.
server {
listen 80 default_server;
...
location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /usr/share/nginx/html;
}
location = /.well-known/acme-challenge/ {
return 404;
}
}
Nginx 다시 불 러 오기:
nginx -s reload
STEP 3: SSL 인증서 신청[root]# certbot certonly --webroot -w /usr/share/nginx/html/ -d your.domain.com
설치 과정 에서 CA 인증 서 를 업데이트 하 는 데 사용 할 메 일 입력 을 알려 줍 니 다.
설치 에 성공 하면 기본적으로
/etc/letsencrypt/live/your.domain.com/
에서 CA 인증 서 를 생 성 합 니 다.|-- fullchain.pem
|-- privkey.pem
단계 4: Nginx 설정
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name def.com;
root /usr/share/nginx/html;
ssl_certificate "/etc/letsencrypt/live/your.domain.com/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/your.domain.com/privkey.pem";
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
설정 완료, Nginx 다시 불 러 오기
단계 5: 인증서 자동 업데이트
명령 행 에서 먼저 아 날로 그 업데이트 인증 서 를 진행 합 니 다.
certbot renew --dry-run
아 날로 그 업데이트 가 성공 하면
crontab -e
명령 을 사용 하여 자동 업데이트 작업 을 사용 합 니 다.[root]# crontab -e
30 2 * * 1 /usr/bin/certbot renew >> /var/log/le-renew.log
관련 참고
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.