自建Twidere API

反代API

用nginx 新建一个HTTPS网站(强烈建议不适用HTTP传输,会被墙)。
https://gist.github.com/mariotaku/f1d61ec9cded3b0ed01f049bb5ddd840

Settings on Twidere:
API URL Format: https://your-host/[DOMAIN.]twitter.com/
Uncheck “Same OAuth signing URL”
Uncheck “No verion suffix”
Password login recommended.
upstream twitter_userstream {
 server userstream.twitter.com:443;

keepalive 300;
}

server {
 listen 443 ssl http2;
 server_name [YOUR-SERVER-NAME-HERE];

ssl_certificate [/path/to/ssl/certificate/cert.pem];
 ssl_certificate_key [/path/to/ssl/certificate/privkey.pem];

location ~ ^/userstream\.twitter\.com/(.*) {
 resolver 8.8.8.8;
 proxy_pass https://twitter_userstream/$1$is_args$args;
 proxy_cookie_domain twitter.com $server_name;
 proxy_buffering off; # Turn off buffer in order to get stream as-is
 proxy_set_header Host userstream.twitter.com;
 proxy_http_version 1.1; # This was necessary!!!
 }

location ~ ^/([\w\d-_]+)\.twitter\.com/(.*) {
 resolver 8.8.8.8;
 proxy_pass https://$1.twitter.com/$2$is_args$args;
 proxy_cookie_domain twitter.com $server_name;
 }

location / {
 root [/path/to/welcome/file];
 }
}


反代图片

使用api反代时候,若不使用ss,有时候会不显示图片,原因是Twidere默认API无法加载图片。可以搭建Thumbor实现图片反代。

安装依赖

 

apt-get install \

python-pip python-opencv \

libjpeg-dev libpng-dev libwebp-dev libtiff-dev libjasper-dev \

libgtk2.0-dev python-numpy python-pycurl python-tornado webp

从源码编译,如果编译过程中有依赖未满足请自行解决。
apt-get install build-essential libssl-dev libffi-dev python-dev
git clone https://github.com/thumbor/thumbor && cd thumbor && python setup.py install

 

测试一下是否安装成功

thumbor --help

然后使用下面命令即可运行。 
thumbor-config > ./thumbor.conf # 生成配置文件
thumbor --port=18888 --conf=thumbor.conf 

nginx反代thumbor

在https服务器的server标签内,添加一个location根目录(/),作为thumbor代理。

server { 
 listen 80;
return 301 https://$server_name$request_uri;

}
server
{
listen 443 ssl http2; #lnmp1.3+版本默认支持http2,可以加上http2,lnmp1.2版本默认支持spdy,可以加上spdy
server_name tu.x1t.win; ##这里是你的域名
index index.html index.htm index.php default.html default.htm default.php;
root /var/www/tu.xin1.win; #网站目录
ssl_certificate /etc/letsencrypt/live/tu.x1t.win/fullchain.pem; #前面生成的证书,改一下里面的域名就行
ssl_certificate_key /etc/letsencrypt/live/tu.x1t.win/privkey.pem; #前面生成的密钥,改一下里面的域名就行

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;



location / 
{
 proxy_pass http://127.0.0.1:28888$request_uri; 
 proxy_redirect off; 
 proxy_set_header X-Real-IP $remote_addr; 
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
}

access_log off;
}


screen -dmS "thumbor_screen" thumbor --port=18888 --conf=thumbor.conf
nginx -s reload

 

 

此条目发表在日常分类目录。将固定链接加入收藏夹。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注