nginx 反向代理 twitter API

适合于有国外VPS的用户搭建自己的twitter API proxy。

可以运用到gravity,mixero这类支持修改API Proxy的客户端中。

如果愿意,也可以修改端口为443并加入证书文件,配置成HTTPS的API Proxy。

网上也有流传许多配置成两个域名的(例如一个api.******,一个search.******)方案,不过不知道为什么在我的gravity上无法工作,因此最终配置成了一个域名下的两个”目录”的形式。下面是我的配置文件:

server {
        listen       80;
        server_name  [YOUR_PROXY_DOMAIN_HERE];

        access_log  /var/log/nginx/twitter_api.access.log;

        location /api {
                proxy_set_header X-Real-IP $remote_addr;
                rewrite /api$ /api/;
                rewrite /api/(.*) /$1 break;
                proxy_pass https://twitter.com;
        }

        location /search {
                proxy_set_header X-Real-IP $remote_addr;
                rewrite /search$ /search/;
                rewrite /search/(.*) /$1 break;
                proxy_pass https://search.twitter.com;
        }
}

配置完成后将Twitter API的地址改为:http://[YOUR_PROXY_DOMAIN_HERE]/api,Twitter Search API的地址改为http://[YOUR_PROXY_DOMAIN_HERE]/search。

2 Responses

Leave a Comment

(Necessary)

(Necessary, will not be published)

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.