用 nginx 反代 Twitter

Desktop 站点配置

server
{
    listen 80;
    listen 443 ssl spdy;
    ssl_certificate /etc/ssl/jude.crt;
    ssl_certificate_key /etc/ssl/jude.key;
    server_name t.ex.com;
    if ($server_port = 80) {
        rewrite ^/(.*)$ https://t.ex.com/$1 redirect;
    }
    location /robots.txt{
        alias /me/proxy/robots.txt;
    }
    location / {
        proxy_hide_header content-security-policy;
        proxy_set_header Accept-Encoding "";
        subs_filter_types application/javascript text/javascript application/json;
        proxy_set_header User-Agent "Opera/9.80 (Windows NT 6.2; WOW64) Presto/2.12.388 Version/12.14";
        proxy_cookie_domain .twitter.com t.ex.com;
        proxy_pass https://mobile.twitter.com/;
        subs_filter mobile.twitter.com t.ex.com;
        subs_filter '://t.co' 's://t.ex.com/t.co';
        subs_filter '://ma.example.com' '://t.ex.com/ma.example.com';
        subs_filter '://pbs.example.com' '://t.ex.com/pbs.example.com';
        subs_filter '://twitter.com' '://t.ex.com/twitter.com';
    }
    location /t.co {
        proxy_pass http://t.co/;
        proxy_redirect http://twitter.com https://t.ex.com/$1;
    }
    location /ma.example.com {
        proxy_pass https://ma.example.com/;
    }
    location /pbs.example.com {
        proxy_pass https://pbs.example.com/;
    }
    location /twitter.com {
        proxy_hide_header content-security-policy;
        proxy_pass https://twitter.com/;
        proxy_set_header Accept-Encoding "";
        proxy_set_header User-Agent "Opera/9.80 (Windows NT 6.2; WOW64) Presto/2.12.388 Version/12.14";
        subs_filter 't.co' 't.ex.com/t.co';
        subs_filter 'ma.example.com' 't.ex.com/ma.example.com';
        subs_filter 'pbs.example.com' 't.ex.com/pbs.example.com';
        subs_filter 'twitter.com' 't.ex.com/twitter.com';
    }
}

Mobile 站点配置

server
{
    # auth_basic "hello";
    # auth_basic_user_file /me/proxy/passwd;
    listen 80;
    listen 443 ssl spdy;
    ssl_certificate /etc/ssl/ex.crt;
    ssl_certificate_key /etc/ssl/ex.key;
    server_name tt.ex.com;
    if ($server_port = 80) {
        rewrite ^/(.*)$ https://tt.ex.com/$1 redirect;
    }
    location /robots.txt{
        alias /me/proxy/robots.txt;
    }
    location / {
        proxy_hide_header content-security-policy;
        proxy_set_header Accept-Encoding '';
        proxy_pass https://twitter.com/;
        proxy_cookie_domain .twitter.com tt.ex.com;
        subs_filter_types application/javascript text/javascript application/json;
        subs_filter 'twitter.com' 'tt.ex.com';
        subs_filter '//t.co' '//tt.ex.com/t.co';
        subs_filter '\/\/t.co' '\/\/tt.ex.com\/t.co';
        subs_filter 'mobile.tt.ex.com' 't.ex.com';
        subs_filter twitter.com tt.ex.com;
        subs_filter 'abs.example.com' 'tt.ex.com/abs.example.com';
        subs_filter 'pbs.example.com' 'tt.ex.com/pbs.example.com';
        subs_filter 'o.example.com' 'tt.ex.com/o.example.com';
        subs_filter 'amp.example.com' 'tt.ex.com/amp.example.com';
        subs_filter 'ton.example.com' 'tt.ex.com/ton.example.com';
    }
    location /t.co {
        proxy_pass http://t.co/;
        proxy_redirect http://twitter.com https://tt.ex.com/$1;
    }
    location /abs.example.com {
        proxy_pass http://abs.example.com/;
        proxy_cookie_domain twitter.com tt.ex.com;
        proxy_set_header Accept-Encoding '';
        subs_filter_types application/javascript text/javascript;
        subs_filter twitter.com tt.ex.com;
        subs_filter 'abs.example.com' 'tt.ex.com/abs.example.com';
        subs_filter 'pbs.example.com' 'tt.ex.com/pbs.example.com';
        subs_filter 'o.example.com' 'tt.ex.com/o.example.com';
        subs_filter 'amp.example.com' 'tt.ex.com/amp.example.com';
        subs_filter 'ton.example.com' 'tt.ex.com/ton.example.com';
    }
    location /pbs.example.com {
        proxy_pass http://pbs.example.com/;
        proxy_set_header Accept-Encoding '';
        subs_filter_types application/javascript text/javascript;
        subs_filter twitter.com tt.ex.com;
        subs_filter 'abs.example.com' 'tt.ex.com/abs.example.com';
        subs_filter 'pbs.example.com' 'tt.ex.com/pbs.example.com';
        subs_filter 'o.example.com' 'tt.ex.com/o.example.com';
        subs_filter 'amp.example.com' 'tt.ex.com/amp.example.com';
        subs_filter 'ton.example.com' 'tt.ex.com/ton.example.com';
    }
    location /amp.example.com {
        proxy_pass https://amp.example.com/;
        proxy_set_header Accept-Encoding '';
        subs_filter_types application/javascript text/javascript;
        subs_filter twitter.com tt.ex.com;
        subs_filter 'abs.example.com' 'tt.ex.com/abs.example.com';
        subs_filter 'pbs.example.com' 'tt.ex.com/pbs.example.com';
        subs_filter 'o.example.com' 'tt.ex.com/o.example.com';
        subs_filter 'amp.example.com' 'tt.ex.com/amp.example.com';
        subs_filter 'ton.example.com' 'tt.ex.com/ton.example.com';
    }
    location /ton.example.com {
        proxy_pass https://ton.example.com/;
        proxy_set_header Accept-Encoding '';
        subs_filter_types application/javascript text/javascript;
        subs_filter twitter.com tt.ex.com;
        subs_filter 'abs.example.com' 'tt.ex.com/abs.example.com';
        subs_filter 'pbs.example.com' 'tt.ex.com/pbs.example.com';
        subs_filter 'o.example.com' 'tt.ex.com/o.example.com';
        subs_filter 'amp.example.com' 'tt.ex.com/amp.example.com';
        subs_filter 'ton.example.com' 'tt.ex.com/ton.example.com';
    }
}