目标:nginx配置多个https域名
查看nginx是否支持支持TLS协议的SNI扩展
1 2 3 4 5 6 7
| root@iZj6cgoyl5x6opizfwaukrZ:~# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.17.0 built by gcc 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1) built with OpenSSL 1.1.1 11 Sep 2018 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl-opt=enable-tlsext --with-pcre=./pcre-8.35 root@iZj6cgoyl5x6opizfwaukrZ:~#
|
如果出现上面的TLS SNI support enabled,则略过第一步
更新nginx
1 2 3 4 5 6
| [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.2k \ --with-openssl-opt="enable-tlsext"
|
其中openssl一般系统自带,可不添加
命令实行后建议,备份nginx.conf,进行重新安装,即make install
增加nginx的配置
直接增加server级的ssl配置即可
今天早上想给自己的服务器添加ssl证书,上传证书,配置证书后发现nginx没有配置ssl_module,只好自行添加了
1 2
| root@instance-0vy61lkh:/maxec/runtime/installer/nginx-1.14.2# nginx -s reload nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:99
|
首先,需要重新编译源码
1 2 3 4 5 6
| root@instance-0vy61lkh:/maxec/runtime/installer/nginx-1.14.2# cd ... root@instance-0vy61lkh:/maxec/runtime/installer/nginx-1.14.2# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module ... /maxec/runtime/installer/nginx-1.14.2/ root@instance-0vy61lkh:/maxec/runtime/installer/nginx-1.14.2# make
|
这一步千万不能 make install ;不然会把之前已经安装的nginx 覆盖掉
除非你已经备份了配置文件
如果中间发现缺少openssl库,可通过以下命令安装
1 2
| sudo apt-get install openssl sudo apt-get install libssl-dev
|
现在,检查我们的安装是否生效
1 2 3 4 5 6 7 8 9 10
| root@instance-0vy61lkh:/usr/local/nginx# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.14.2 built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11) built with OpenSSL 1.0.2g 1 Mar 2016 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module root@instance-0vy61lkh:/usr/local/nginx/conf# /etc/init.d/nginx start ... root@instance-0vy61lkh:/usr/local/nginx/conf# netstat -lnp|grep nginx ...
|
参考:
https://www.cnblogs.com/piscesLoveCc/p/6120875.html