更详细的参数设定请参考:https://segmentfault.com/a/1190000002866627
步骤:
1.生成一个权威的ssl证书对(如果自己颁发的话,那么https是不被浏览器认可的,就是https上面会有一个大红叉)
推荐一个免费的网站:https://www.startssl.com/(注册邮箱:公司邮箱)
startssl的操作教程看这个:http://www.freehao123.com/startssl-ssl/
2.根据ssl.key和ssl.crt部署nginx
首先nginx需要支持ssl_module,然后修改nginx.conf如下
server {
listen 443;
server_name wx.ltanx.cn;
ssl on;
ssl_certificate ../key/1_wx.ltanx.cn_bundle.crt;
ssl_certificate_key ../key/ltanx_nopass.key;#这个是有密码的,重启或者reload nginx的时候会提示密码
ssl_session_timeout 30m;#默认时间只有5分钟,如果5分钟就挂掉未免太短了
}在相应的位置放置crt文件和key文件,注意到这边的key是nopassword的,就是重启nginx的时候,不需要输入密码。
ltanx_nopass.key是根据ltanx.key生成的,生成命令如下:
openssl rsa -in -ltanx.keyout ltanx_nopass.key 然后输入密码就行
到这里重启nginx后就可以访问https://wx.ltanx.cn了
3.80端口重定向到443端口
server {
listen 80;
server_name wx.ltanx.cn;
rewrite ^(.*) https://$server_name$1 permanent;
### 使用return的效率会更高
# return 301 https://$server_name$request_uri;
}
本文出自 “lly0205.mofile.com” 博客,请务必保留此出处http://481814.blog.51cto.com/471814/1835713
原文:http://481814.blog.51cto.com/471814/1835713