V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
lslqtz
V2EX  ›  问与答

用 Nginx 反代 YouTube,部分资源没替换成功

  •  
  •   lslqtz · 2016-07-19 08:32:05 +08:00 · 11320 次点击
    这是一个创建于 3056 天前的主题,其中的信息可能已经有所发展或是发生改变。
    不知道是因为什么原因,贴配置。。
    界面等都正常了,而且我把 https 全部替换为 http 了(最极端的方式)。。
    目前首页只有广告因为反向代理没法正常加载,其他都没问题。
    附图:
    https://ooo.0o0.ooo/2016/07/18/578d782eaa339.png
    https://ooo.0o0.ooo/2016/07/18/578d782f4924b.png

    视频页 Console 的部分信息如下:
    # 不知为何替换失败 https://r3---sn-25g7sn7d.googlevideo.com/crossdomain.xml net::ERR_CONNECTION_TIMED_OUT
    # 不知为何替换失败 http 打开反代被重置 https 因为泛域名和没法替换而搁置
    Uncaught Error: Untrusted URL: https://r3---sn-25g7sn7d.googlevideo.com/videoplayback?mm=31&ip=5.196.94.97 … 362%2C9439417%2C9439477%2C9439652%2C9439952%2C9442253&cpn=mbtEGMRtpHVgZrWl
    at Error (native)
    at Mr ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:917:47)
    at Jr.get ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:4720:30)
    at es.set ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:4732:82)
    at us ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:958:127)
    at g.h.Nn ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:5273:231)
    at g.h.start ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:5272:89)
    at HI ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:2021:312)
    at .<anonymous> ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:2039:177)
    at Array.forEach (native)

    # 偶尔多刷新几次,会变成https没替换成功,但是域名替换成功了。
    base.js:7069 Uncaught Error: Untrusted URL: https://r3---sn-25g7sn7d.googlevideo.acgn.ren/videoplayback?keepalive=yes&l…1NvamAXVEUcWY1H_ECo-pz25G&clen=2420516&ip=5.196.94.97&cpn=HL9O0lPPW_Hsw-EA
    at Error (native)
    at Mr ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:917:47)
    at Jr.get ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:4720:30)
    at es.set ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:4732:82)
    at us ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:958:127)
    at g.h.Nn ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:5273:231)
    at g.h.start ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:5272:89)
    at HI ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:2021:312)
    at .<anonymous> ( http://s.ytimg.acgn.ren/yts/jsbin/player-zh_CN-vflo3vXhM/base.js:2039:177)
    at Array.forEach (native)

    # Nginx 上的相关配置
    server {
    listen 80;
    server_name y.acgn.ren;

    location / {
    proxy_cache content;
    proxy_cache_valid 200 302 1h;
    proxy_cache_valid 404 1m;
    proxy_cache_key $host$uri$is_args$args;
    proxy_cookie_domain youtube.com y.acgn.ren;
    proxy_pass https://www.youtube.com;
    proxy_redirect https://www.youtube.com/ /;
    proxy_set_header Accept-Encoding "";
    proxy_set_header Accept-Language "zh-CN";
    proxy_set_header Cookie "VISITOR_INFO1_LIVE=8fW9qUyX2S8; YSC=5FtyWFk_blM; PREF=f1=50000000&f5=30; goojf=8fc97fd8f5df8b450e3b3fe74882aa62c2IAAABBR3lhbkhOeEJjU1A1WmJKZEtOcEdDcDZ1ZGVjTjh6NUVBSlBpdUh0SHhnNkJrMU9sSE5iemFnb0Z2cUpiRVJBOGRFV1l5bjk0TzFyV2cxbTRqbjQ1a1p4SU9xZTBKbkJJQQ==";
    proxy_set_header Host "www.youtube.com";
    proxy_set_header User-Agent $http_user_agent;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    sub_filter https://www.youtube.com http://y.acgn.ren;
    sub_filter http://www.youtube.com http://y.acgn.ren;
    sub_filter //www.youtube.com //y.acgn.ren;
    sub_filter www.youtube.com y.acgn.ren;
    sub_filter https://www.google.com http://www.acgn.ren;
    sub_filter http://www.gstatic.com http://www.acgn.ren/gstatic;
    sub_filter https://ssl.gstatic.com http://www.acgn.ren/gstatic;
    sub_filter https://s.ytimg.com http://s.ytimg.acgn.ren;
    sub_filter https://i.ytimg.com http://i.ytimg.acgn.ren;
    sub_filter https://yt3.ggpht.com http://yt3.ggpht.acgn.ren;
    sub_filter http://s.ytimg.com http://s.ytimg.acgn.ren;
    sub_filter http://i.ytimg.com http://i.ytimg.acgn.ren;
    sub_filter http://yt3.ggpht.com http://yt3.ggpht.acgn.ren;
    sub_filter //s.ytimg.com //s.ytimg.acgn.ren;
    sub_filter //i.ytimg.com //i.ytimg.acgn.ren;
    sub_filter //yt3.ggpht.com //yt3.ggpht.acgn.ren;
    sub_filter //s.ytimg.com //s.ytimg.acgn.ren;
    sub_filter //i.ytimg.com //i.ytimg.acgn.ren;
    sub_filter //yt3.ggpht.com //yt3.ggpht.acgn.ren;
    sub_filter s.ytimg.com s.ytimg.acgn.ren;
    sub_filter i.ytimg.com i.ytimg.acgn.ren;
    sub_filter yt3.ggpht.com yt3.ggpht.acgn.ren;
    sub_filter s.ytimg.com s.ytimg.acgn.ren;
    sub_filter i.ytimg.com i.ytimg.acgn.ren;
    sub_filter yt3.ggpht.com yt3.ggpht.acgn.ren;
    sub_filter https:// http://;
    sub_filter https: http:;
    sub_filter googlevideo.com googlevideo.acgn.ren;
    sub_filter www.youtube.com y.acgn.ren;
    sub_filter www.google.com www.acgn.ren;
    sub_filter www.gstatic.com www.acgn.ren/gstatic;
    sub_filter ssl.gstatic.com www.acgn.ren/gstatic;
    sub_filter_types text/javascript application/javascript text/css text/x-cross-domain-policy;
    sub_filter_once off;
    }
    }

    server {
    listen 80;
    server_name s.ytimg.acgn.ren;

    location / {
    proxy_cache content;
    proxy_cache_valid 200 302 1h;
    proxy_cache_valid 404 1m;
    proxy_cache_key $host$uri$is_args$args;
    proxy_pass https://s.ytimg.com;
    proxy_redirect https://s.ytimg.com/ /;
    proxy_set_header Accept-Encoding "";
    proxy_set_header Accept-Language "zh-CN";
    proxy_set_header Cookie $http_cookie;
    proxy_set_header Host "s.ytimg.com";
    proxy_set_header User-Agent $http_user_agent;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    sub_filter https://www.youtube.com http://y.acgn.ren;
    sub_filter http://www.youtube.com http://y.acgn.ren;
    sub_filter //www.youtube.com //y.acgn.ren;
    sub_filter www.youtube.com y.acgn.ren;
    sub_filter https://www.google.com http://www.acgn.ren;
    sub_filter http://www.gstatic.com http://www.acgn.ren/gstatic;
    sub_filter https://ssl.gstatic.com http://www.acgn.ren/gstatic;
    sub_filter https://s.ytimg.com http://s.ytimg.acgn.ren;
    sub_filter https://i.ytimg.com http://i.ytimg.acgn.ren;
    sub_filter https://yt3.ggpht.com http://yt3.ggpht.acgn.ren;
    sub_filter http://s.ytimg.com http://s.ytimg.acgn.ren;
    sub_filter http://i.ytimg.com http://i.ytimg.acgn.ren;
    sub_filter http://yt3.ggpht.com http://yt3.ggpht.acgn.ren;
    sub_filter //s.ytimg.com //s.ytimg.acgn.ren;
    sub_filter //i.ytimg.com //i.ytimg.acgn.ren;
    sub_filter //yt3.ggpht.com //yt3.ggpht.acgn.ren;
    sub_filter //s.ytimg.com //s.ytimg.acgn.ren;
    sub_filter //i.ytimg.com //i.ytimg.acgn.ren;
    sub_filter //yt3.ggpht.com //yt3.ggpht.acgn.ren;
    sub_filter s.ytimg.com s.ytimg.acgn.ren;
    sub_filter i.ytimg.com i.ytimg.acgn.ren;
    sub_filter yt3.ggpht.com yt3.ggpht.acgn.ren;
    sub_filter s.ytimg.com s.ytimg.acgn.ren;
    sub_filter i.ytimg.com i.ytimg.acgn.ren;
    sub_filter yt3.ggpht.com yt3.ggpht.acgn.ren;
    sub_filter https:// http://;
    sub_filter https: http:;
    sub_filter https http;
    sub_filter googlevideo.com googlevideo.acgn.ren;
    sub_filter www.youtube.com y.acgn.ren;
    sub_filter www.google.com www.acgn.ren;
    sub_filter www.gstatic.com www.acgn.ren/gstatic;
    sub_filter ssl.gstatic.com www.acgn.ren/gstatic;
    sub_filter_types text/javascript application/javascript text/css text/x-cross-domain-policy;
    sub_filter_once off;
    }
    }

    server {
    listen 80;
    server_name i.ytimg.acgn.ren;

    location / {
    proxy_cache content;
    proxy_cache_valid 200 302 1h;
    proxy_cache_valid 404 1m;
    proxy_cache_key $host$uri$is_args$args;
    proxy_pass https://i.ytimg.com;
    proxy_redirect https://i.ytimg.com/ /;
    proxy_set_header Accept-Encoding "";
    proxy_set_header Accept-Language "zh-CN";
    proxy_set_header Cookie $http_cookie;
    proxy_set_header Host "i.ytimg.com";
    proxy_set_header User-Agent $http_user_agent;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    sub_filter https://www.youtube.com http://y.acgn.ren;
    sub_filter http://www.youtube.com http://y.acgn.ren;
    sub_filter //www.youtube.com //y.acgn.ren;
    sub_filter www.youtube.com y.acgn.ren;
    sub_filter https://www.google.com http://www.acgn.ren;
    sub_filter http://www.gstatic.com http://www.acgn.ren/gstatic;
    sub_filter https://ssl.gstatic.com http://www.acgn.ren/gstatic;
    sub_filter https://s.ytimg.com http://s.ytimg.acgn.ren;
    sub_filter https://i.ytimg.com http://i.ytimg.acgn.ren;
    sub_filter https://yt3.ggpht.com http://yt3.ggpht.acgn.ren;
    sub_filter http://s.ytimg.com http://s.ytimg.acgn.ren;
    sub_filter http://i.ytimg.com http://i.ytimg.acgn.ren;
    sub_filter http://yt3.ggpht.com http://yt3.ggpht.acgn.ren;
    sub_filter //s.ytimg.com //s.ytimg.acgn.ren;
    sub_filter //i.ytimg.com //i.ytimg.acgn.ren;
    sub_filter //yt3.ggpht.com //yt3.ggpht.acgn.ren;
    sub_filter //s.ytimg.com //s.ytimg.acgn.ren;
    sub_filter //i.ytimg.com //i.ytimg.acgn.ren;
    sub_filter //yt3.ggpht.com //yt3.ggpht.acgn.ren;
    sub_filter s.ytimg.com s.ytimg.acgn.ren;
    sub_filter i.ytimg.com i.ytimg.acgn.ren;
    sub_filter yt3.ggpht.com yt3.ggpht.acgn.ren;
    sub_filter s.ytimg.com s.ytimg.acgn.ren;
    sub_filter i.ytimg.com i.ytimg.acgn.ren;
    sub_filter yt3.ggpht.com yt3.ggpht.acgn.ren;
    sub_filter https:// http://;
    sub_filter https: http:;
    sub_filter googlevideo.com googlevideo.acgn.ren;
    sub_filter www.youtube.com y.acgn.ren;
    sub_filter www.google.com www.acgn.ren;
    sub_filter www.gstatic.com www.acgn.ren/gstatic;
    sub_filter ssl.gstatic.com www.acgn.ren/gstatic;
    sub_filter_types text/javascript application/javascript text/css text/x-cross-domain-policy;
    sub_filter_once off;
    }
    }

    server {
    listen 80;
    server_name yt3.ggpht.acgn.ren;

    location / {
    proxy_cache content;
    proxy_cache_valid 200 302 1h;
    proxy_cache_valid 404 1m;
    proxy_cache_key $host$uri$is_args$args;
    proxy_pass https://yt3.ggpht.com;
    proxy_redirect https://yt3.ggpht.com/ /;
    proxy_set_header Accept-Encoding "";
    proxy_set_header Accept-Language "zh-CN";
    proxy_set_header Cookie $http_cookie;
    proxy_set_header Host "yt3.ggpht.com";
    proxy_set_header User-Agent $http_user_agent;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    sub_filter https://www.youtube.com http://y.acgn.ren;
    sub_filter http://www.youtube.com http://y.acgn.ren;
    sub_filter //www.youtube.com //y.acgn.ren;
    sub_filter www.youtube.com y.acgn.ren;
    sub_filter https://www.google.com http://www.acgn.ren;
    sub_filter http://www.gstatic.com http://www.acgn.ren/gstatic;
    sub_filter https://ssl.gstatic.com http://www.acgn.ren/gstatic;
    sub_filter https://s.ytimg.com http://s.ytimg.acgn.ren;
    sub_filter https://i.ytimg.com http://i.ytimg.acgn.ren;
    sub_filter https://yt3.ggpht.com http://yt3.ggpht.acgn.ren;
    sub_filter http://s.ytimg.com http://s.ytimg.acgn.ren;
    sub_filter http://i.ytimg.com http://i.ytimg.acgn.ren;
    sub_filter http://yt3.ggpht.com http://yt3.ggpht.acgn.ren;
    sub_filter //s.ytimg.com //s.ytimg.acgn.ren;
    sub_filter //i.ytimg.com //i.ytimg.acgn.ren;
    sub_filter //yt3.ggpht.com //yt3.ggpht.acgn.ren;
    sub_filter //s.ytimg.com //s.ytimg.acgn.ren;
    sub_filter //i.ytimg.com //i.ytimg.acgn.ren;
    sub_filter //yt3.ggpht.com //yt3.ggpht.acgn.ren;
    sub_filter s.ytimg.com s.ytimg.acgn.ren;
    sub_filter i.ytimg.com i.ytimg.acgn.ren;
    sub_filter yt3.ggpht.com yt3.ggpht.acgn.ren;
    sub_filter s.ytimg.com s.ytimg.acgn.ren;
    sub_filter i.ytimg.com i.ytimg.acgn.ren;
    sub_filter yt3.ggpht.com yt3.ggpht.acgn.ren;
    sub_filter https:// http://;
    sub_filter https: http:;
    sub_filter googlevideo.com googlevideo.acgn.ren;
    sub_filter www.youtube.com y.acgn.ren;
    sub_filter www.google.com www.acgn.ren;
    sub_filter www.gstatic.com www.acgn.ren/gstatic;
    sub_filter ssl.gstatic.com www.acgn.ren/gstatic;
    sub_filter_types text/javascript application/javascript text/css text/x-cross-domain-policy;
    sub_filter_once off;
    }
    }

    server {
    listen 80;
    server_name ~^(.+).googlevideo.acgn.ren$;

    location / {
    proxy_cache content;
    proxy_cache_valid 200 302 1h;
    proxy_cache_valid 404 1m;
    proxy_cache_key $host$uri$is_args$args;
    proxy_pass https://r3---sn-25g7sn7d.googlevideo.com;
    proxy_set_header Accept-Encoding "";
    proxy_set_header Accept-Language "zh-CN";
    proxy_set_header Cookie $http_cookie;
    proxy_set_header Host $1.googlevideo.com;
    proxy_set_header User-Agent $http_user_agent;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    sub_filter *.youtube.com *.y.acgn.ren;
    sub_filter_types text/x-cross-domain-policy;
    sub_filter_once off;
    }
    }
    21 条回复    2018-02-11 17:18:08 +08:00
    alect
        1
    alect  
       2016-07-19 08:59:24 +08:00
    第一次见到真有人拿 nginx 反代油管啊,傻逼谷歌搞了那么多域名只能考虑其他方法,反代好累
    tony1016
        2
    tony1016  
       2016-07-19 09:27:14 +08:00
    确实大开眼界
    xiaoz
        3
    xiaoz  
       2016-07-19 09:42:32 +08:00
    楼主 V5 ,用了那么多次 sub_filter
    Zohar
        4
    Zohar  
       2016-07-19 09:47:51 +08:00 via Android
    lslqtz
        5
    lslqtz  
    OP
       2016-07-19 09:54:48 +08:00
    @alect +1
    @xiaoz 纯乱搞 23333333333
    sub_filter https http; 炒鸡极端 2333333
    lslqtz
        6
    lslqtz  
    OP
       2016-07-19 09:55:16 +08:00
    @alect 但是替换不了才是问题啊,蛋疼 我没有找到那个 https 去哪里了
    lslqtz
        7
    lslqtz  
    OP
       2016-07-19 09:55:37 +08:00
    @Zohar subs ?这不是和 sub 一样嘛。。
    两个应该都支持正则表达式的
    alect
        8
    alect  
       2016-07-19 10:02:45 +08:00
    楼主应该考虑用 sniproxy …… nginx 反代太累了
    Zohar
        9
    Zohar  
       2016-07-19 10:08:49 +08:00 via Android
    @lslqtz sub 理论上只能替换一次才对?
    server
        10
    server  
       2016-07-19 10:09:06 +08:00
    66666 ,请参考 ss
    crazycen
        11
    crazycen  
       2016-07-19 10:14:50 +08:00
    不敢反代了,分分钟 IP 被封。。。
    lslqtz
        12
    lslqtz  
    OP
       2016-07-19 10:15:06 +08:00
    @alect 因为我要更换域名而且要公开。。
    @Zohar sub_filter_once off;
    lslqtz
        13
    lslqtz  
    OP
       2016-07-19 10:15:25 +08:00
    @crazycen 百度云加速国内节点大法好,反正 IP 提个 ticket 就换~
    Tink
        14
    Tink  
       2016-07-19 10:34:27 +08:00
    强。。。。。

    有个模块叫 replace-filter-nginx-module
    zanewell
        15
    zanewell  
       2016-07-19 10:34:28 +08:00 via iPhone
    @alect sniproxy 有无好办法防范代理服务器 ip 暴露?
    lslqtz
        16
    lslqtz  
    OP
       2016-07-19 10:49:38 +08:00
    @zanewell 做 CDN 。
    zingl
        17
    zingl  
       2016-07-19 11:29:30 +08:00
    首先,你见过有人反代 YT 成功的么?
    其次,反代不成功的 URL 你在页面源码里找得到么?
    lslqtz
        18
    lslqtz  
    OP
       2016-07-19 12:09:41 +08:00
    @zingl 找不到。。
    YingJie
        19
    YingJie  
       2016-07-19 19:32:10 +08:00 via Android
    题外话:反代不如弄镜像站,
    jsteward
        20
    jsteward  
       2016-07-25 19:25:09 +08:00
    小问题:移动端还是会跳到 m.youtube.com
    bilibiliQQ
        21
    bilibiliQQ  
       2018-02-11 17:18:08 +08:00
    试试这个
    http://2tube。js。org
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2802 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 05:47 · PVG 13:47 · LAX 21:47 · JFK 00:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.