Nginx配置多個HTTPS域名的方法
阿新 • • 發佈:2019-01-04
參考URL:https://www.jb51.net/article/117697.htm
?12345678910111213141516171819202122232425262728293031323334353637383940 | ... 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 { } } |
https://www.cnblogs.com/beyang/p/7718463.html
最近在玩微信小程式,手頭有:
- 一臺雲伺服器:CentOS 7
- 多個一級域名
開發測試過程中,因為某些原因,想要讓手頭的A、B域名同時指向雲伺服器的443埠,支援HTTPS。
Nginx支援TLS協議的SNI擴充套件(同一個IP上可以支援多個不同證書的域名),只需要重新安裝Nginx,使其支援TLS即可。
準備工作
yum -y install gcc
yum -y install gcc-c++
yum install -y zlib-devel
wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.35/pcre-8.38.tar.gz
tar zxvf pcre-8.38
只要解壓縮就可以
安裝Nginx
wget http://nginx.org/download/nginx-1.12.0.tar.gztar zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/openssl-1.0.2o --with-openssl-opt="enable-tlsext" --with-pcre=/usr/local/pcre-8.38
配置Nginx
在購買域名的時候,如果域名提供商有免費的SSL證書,就直接用;如果沒有的話,可以使用 Let's Encript 生成免費的CA證書。
開啟Nginx的配置:vi /usr/local/nginx/nginx.conf
12345678910111213141516171819202122232425262728293031323334353637383940 | ... 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;
|