nginx反代多说头像+表情
多说的https支持并不是特别好,尤其是头像跟表情,依然走的http协议,会让你的小绿锁消失,无奈只能本地反代这些头像。
直接上nginx规则,请自行将cdn.run.la替换成你自己的域名,因为我是使用cdn进行缓存的,所以nginx并没有配置缓存。
nginx规则
resolver 119.29.29.29 223.5.5.5 valid=600s;
resolver_timeout 10s;
location ~ ^/duoshuo/(\w+\.)(t\.sinajs\.cn|bdimg\.com|cdncache\.org|douban\.com|gravatar\.com|qlogo\.cn|sinaimg\.cn|xnimg\.cn)(\/.*)$ {
proxy_connect_timeout 10s;
proxy_read_timeout 10s;
proxy_set_header Host $1$2;
proxy_pass http://$1$2$3;
proxy_http_version 1.1;
proxy_set_header Connection "";
expires 30d;
}
location /duoshuo/embed.js {
proxy_connect_timeout 10s;
proxy_read_timeout 10s;
sub_filter 'avatarUrl:function(e){return e.avatar_url||rt.data.default_avatar_url}' 'avatarUrl:function(e){var avatar_url=e.avatar_url;if(!avatar_url){if(rt.data.default_avatar_url.indexOf("http:")){rt.data.default_avatar_url=rt.data.default_avatar_url.replace("http:","https:")}return rt.data.default_avatar_url.replace("http:","https:")}else{if(avatar_url.indexOf("qzapp.qlogo.cn")!=-1||avatar_url.indexOf("wx.qlogo.cn")!=-1){return"//cdn.run.la/duoshuo/"+avatar_url.replace("","")}else if(avatar_url.indexOf("q.qlogo.cn")!=-1||avatar_url.indexOf("app.qlogo.cn")!=-1||avatar_url.indexOf("avatar.duoshuo.com")!=-1){return avatar_url.replace("http:","https:")}else{return"//cdn.run.la/duoshuo/"+avatar_url.replace("","")}}}';
sub_filter 'r=s.author;' 'r=s.author;if(s.message.indexOf("http:")!=-1){s.message=s.message.replace(/src=(["|\'])http:\/\//g,"src=$1//cdn.run.la/duoshuo/")}';
sub_filter 'S.STATIC_URL+"/images/smilies/"+s;' 'S.STATIC_URL+"/images/smilies/"+s,i=i.replace("http://","//cdn.run.la/duoshuo/");';
sub_filter_once on;
sub_filter_types application/x-javascript;
proxy_set_header Host static.duoshuo.com;
proxy_set_header Accept-Encoding '';
proxy_pass http://static.duoshuo.com/embed.js;
proxy_http_version 1.1;
proxy_set_header Connection "";
expires 30d;
}
引入embed.js
文件
<script src="//cdn.run.la/duoshuo/embed.js" data-no-instant></script>
参考文档
https://imququ.com/post/duoshuo-and-https.html
https://qqdie.com/archives/duoshuoxhttps.html