介绍http形式访问
我直接参考了官方文档上关于在CentOS 7上用nginx来让网站支持https的教程 1.下载 sudo yum install certbot python2-certbot-nginx 2.执行命令
如果不在这个目录可以用–nginx-server-root这个参数来指定 certbot --nginx --nginx-server-root=/yourpath -d www. 如果要为多个域名生成的话
或者每次指定一个,执行多次 如果选 1,则通过 HTTP 和 HTTPS 都可以访问。 中途中可能会遇到各种环境问题,Google解决即可。 我说一个我遇到的坑,我原来编译的时候没有选择SSL module,所以我得重新编译一下,编译完成之后我是用如下命令重启的 nginx -s reload 结果https访问一直有问题,后来我才意识到。sbin目录下重新生成的nginx得重启才能生效。 此时http://www.和https://www.就都可以访问了 nginx.conf配置
最后面的5行就是前面的命令自动帮你生成的,非常方便,都不用自己配置。 前端怎么写?为了让前端在访客通过http方式访问的时候调用http接口。通过https访问的时候调用https接口,我是这样做的 nb.js var conf = { serverHot : window.location.origin};var _nb = { request: function (param) { var _this = this; $.ajax({ type : param.method || 'get', url : param.url || '', dataType : param.type || 'json', data : param.data || '', xhrFields : {withCredentials: true}, crossDomain: true, contentType: param.contentType || 'application/x-www-form-urlencoded;charset=UTF-8', success: function (res) { typeof param.success === 'function' && param.success(res.data, res.msg); }, error: function (err) { typeof param.error === 'function' && param.error(err.statusText); } }) }, // 获取服务器地址 getServerUrl : function(path) { return conf.serverHot + path; }}module.exports = _nb;123456789101112131415161718192021222324252627282930 window.location.origin为拿到https://www.类似这样的请求地址,可以在浏览器自己试一下
userInfo为请求参数 自动续期Let’s Encrypt 的证书90天就过期了,所以,你还要设置上自动化的更新脚本,最容易的莫过于使用 crontab 了。使用 crontab -e 命令加入如下的定时作业(每个月都强制更新一下)输入 0 0 * * * certbot renew 专栏 Java面试通关100问 |
|