一臺服務器,兩個域名html
首先購買https,獲取到CA證書,兩個域名就獲得兩套證書linux
第二步:如今就是Nginx和OpenSSL的安裝與配置(這裏注意,通常狀況下一個IP只支持一個SSL證書,那麼咱們如今要在一個IP上實現多個SSL證書,就必須讓Nginx支持TLS SNI,因爲默認的OpenSSL是沒有打開TLS SNI的)nginx
1)Nginx支持多域名SSL證書是須要OpenSSL庫支持的,CentOS5.X的OpenSSL庫自己不支持這種特性,須要從新下載編譯,步驟以下:服務器
wget https://www.openssl.org/source/old/0.9.x/openssl-0.9.8zh.tar.gz
tar zxvf ./openssl-0.9.8zh.tar.gzsession
2)下載Nginx,進行配置app
wget http://nginx.org/download/nginx-1.8.0.tar.gztcp
tar zxf nginx-1.8.0.tar.gz ui
cd nginx-1.8.0code
./configure --prefix=/usr/local/nginx1.8.0 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=../openssl-0.9.8zh orm
(此處會報錯:出現pcre庫沒找到或zlib沒找到,
在CentOS下能夠使用 yum -y install pcre-devel zlib-devel 進行安裝缺失的組件
)
make && make install
3)檢查Nginx狀態
/usr/local/nginx1.8.0/sbin/nginx -V
獲得以下結果就說明配置好了:
nginx version: nginx/1.8.0
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-55)
built with OpenSSL 0.9.8zh 3 Dec 2015
TLS SNI support enabled #能夠看到TLS SNI support打開了
configure arguments: --prefix=/usr/local/nginx1.8.0 --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=../openssl-0.9.8zh
第三步:
配置Nginx 應用服務器
證書放置到 Nginx/conf/cert 目錄下
nginx.conf文件以下
http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream shop_wechat { server 127.0.0.1:80; } server { listen 443 ssl; server_name www.test1.com; ssl_certificate cert/214257281110004.pem; ssl_certificate_key cert/214257281110004.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { proxy_pass http://shop_wechat; } } upstream shop_app { server 127.0.0.1:1098; } server { listen 443 ssl; server_name app.test2.com; ssl_certificate cert/214257663690004.pem; ssl_certificate_key cert/214257663690004.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { proxy_pass http://shop_app; } } }
啓動Nginx:報錯-
nginx: [emerg] getpwnam(「www」) failed錯誤
錯誤的緣由是沒有建立www這個用戶,應該在服務器系統中添加www用戶組和用戶www,以下命令:
#/usr/sbin/groupadd -f www
#/usr/sbin/useradd -g www www
最後:訪問下試試看 :https://www.test1.com