haproxy-https-to-http

haproxy 把https转发的时候变成了http

今天接微信API的时候,发现一个很奇怪的问题,本地调试都ok,一旦部署到线上就出问题,后来经过仔细排查,发现我们网站用的是https,很奇怪,haproxy转发的时候会把https转化成http,这是bug吗?待续。

后来证实,这不是haproxy的bug.是由于我们项目使用的是nodejssails框架导致的。

使用express的nodejs应用程序,需要注意,使用代理服务器转发的时候,获取请求协议的时候正确的取值方法是req.headers[‘x-forwarded-proto’],直接取值req.protocol取得值是http,在接入微信授权的时候,本地调试都正常,一旦部署到线上(https),就会提示:config: invalid signature。所以当接入微信API,本地调试一切正常,到线上(https)部署后发现不正常,就应当检查一下授权的地址协议是否正确。

referrer:

https://github.com/nodejs/node-v0.x-archive/issues/6735
https://github.com/expressjs/express/issues/1863

image-preload

图片预加载——显示加载进度

usage

1
2
3
4
5
6
7
8
/**
@param imageArr:预先加载的图片数组,
@param config:
@param update:每加载一张执行一次update函数
@param complete:加载完成所有图片执行该函数
@param silent:true//表示使用默认的加载样式
*/

ImageLoader(imageArr,config)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>imageloader</title>
<script type="text/javascript" src="../imageloader.js"></script>
<link rel="stylesheet" type="text/css" href="../imageloader.css">
</head>
<body>
<h2 style="text-align:center">imageloader demo</h2>
<div id="imageContainer"></div>
<script type="text/javascript">
var imagesArr = ['./images/buy_domain.png','./images/dusk.jpg','./images/malaysia_dusk.jpg','./images/malaysia_sea.jpg'];
var updateFn = function(){
var img = document.createElement('IMG');
img.setAttribute('src',arguments[2]);
document.getElementById('imageContainer').appendChild(img);
}
ImageLoader(imagesArr,{update:updateFn,complete:function(){
alert('All images loaded.');
},silent:true});
</script>

</body>
</html>

源码地址:https://github.com/navyxie/imageloader

web-security

随机token

整个处理流程:

  1. 在需要处理盗刷的接口添加token参数校验
  2. web端在需要处理盗刷页面注入token
  3. Native(IOS,android)通过API形式请求token,在相应的接口请求时带上

服务端生成token

使用redis管理token

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//生成token
Redis.SETEX(token,ttl, 1,cb);
//验证token
Redis.GET(token,function (err, data) {
if(data && data < 4){
//每个token在ttl时间间隔内只能使用3次
self.incrToken(token,tokenPre,cb);
}else{
self.removeToken(token,tokenPre,function(err,data){
cb(null,false);
});
}
});
}

阅读全文 >

粤ICP备18054847号-2
本站总访问量次 本站访客数人 本文总阅读量
{% if theme.baidu_push %} {% endif %}