一台服务器,两个域名
首先购买https,获取到CA证书,两个域名就得到两套证书
第二步:现在就是Nginx和OpenSSL的安装与配置(这里注意,一般情况下一个IP只支持一个SSL证书,那么我们现在要在一个IP上实现多个SSL证书,就必须让Nginx支持TLS SNI,由于默认的OpenSSL是没有打开TLS SNI的)
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.gz
2)下载Nginx,进行配置
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./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
(此处会报错:出现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