您的位置:首页 > 理论基础 > 计算机网络

nginx配置https之使用第三方证书

2016-11-09 14:51 856 查看
1、检查nginx的ssl模块--with-http_ssl_module是否安装,如果没有需要重新编译安装。

[root@huanan1-cloud-test01 ~]# /usr/local/websrv/nginx/sbin/nginx -V
nginx version: nginx/1.6.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
TLS SNI support enabled
configure arguments: --user=nobody --group=nobody --with-http_ssl_module --with-http_stub_status_module --prefix=/usr/local/websrv/nginx-1.6.3/
[root@huanan1-cloud-test01 ~]#
ok!已经安装完成了,不用重新编译安装了。

2、修改nginx配置文件。
在nginx的conf目录下新建key目录来存放证书。
[root@huanan1-cloud-test01 ~]# cd /usr/local/websrv/nginx-1.6.3/conf/
[root@huanan1-cloud-test01 /usr/local/websrv/nginx-1.6.3/conf]# mkdir key
nginx.conf开启ssl,在要配置https的站点目录的server标签里添加52-55行
[root@huanan1-cloud-test01 /usr/local/websrv/nginx-1.6.3/conf]# vim nginx.conf
....

48         listen       80;
49         server_name    test.hrfax.cn hrfax.cn;
50
51         #  添加如下
52         listen 443;
53         ssl on;
54         ssl_certificate key/server.crt;
55         ssl_certificate_key key/server.key;

....


3、上传证书到/usr/local/websrv/nginx/conf/key目录下
[root@huanan1-cloud-test01 /usr/local/websrv/nginx-1.6.3/conf]# ls key/
server.crt  server.key


4、重新reload nginx让配置生效。
[root@huanan1-cloud-test01 /usr/local/websrv/nginx-1.6.3/conf]# ../sbin/nginx -t
nginx: the configuration file /usr/local/websrv/nginx-1.6.3//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/websrv/nginx-1.6.3//conf/nginx.conf test is successful

[root@huanan1-cloud-test01 /usr/local/websrv/nginx-1.6.3/conf]# ../sbin/nginx -s reload

[root@huanan1-cloud-test01 /usr/local/websrv/nginx-1.6.3/conf]# netstat -ntlpua|grep 443
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1908/nginx: master


5、客户端浏览器测试。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  https nginx