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

2016-07-19 08:32:05 +08:00
 lslqtz
不知道是因为什么原因,贴配置。。
界面等都正常了,而且我把 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;
}
}
11368 次点击
所在节点    问与答
21 条回复
alect
2016-07-19 08:59:24 +08:00
第一次见到真有人拿 nginx 反代油管啊,傻逼谷歌搞了那么多域名只能考虑其他方法,反代好累
tony1016
2016-07-19 09:27:14 +08:00
确实大开眼界
xiaoz
2016-07-19 09:42:32 +08:00
楼主 V5 ,用了那么多次 sub_filter
Zohar
2016-07-19 09:47:51 +08:00
lslqtz
2016-07-19 09:54:48 +08:00
@alect +1
@xiaoz 纯乱搞 23333333333
sub_filter https http; 炒鸡极端 2333333
lslqtz
2016-07-19 09:55:16 +08:00
@alect 但是替换不了才是问题啊,蛋疼 我没有找到那个 https 去哪里了
lslqtz
2016-07-19 09:55:37 +08:00
@Zohar subs ?这不是和 sub 一样嘛。。
两个应该都支持正则表达式的
alect
2016-07-19 10:02:45 +08:00
楼主应该考虑用 sniproxy …… nginx 反代太累了
Zohar
2016-07-19 10:08:49 +08:00
@lslqtz sub 理论上只能替换一次才对?
server
2016-07-19 10:09:06 +08:00
66666 ,请参考 ss
crazycen
2016-07-19 10:14:50 +08:00
不敢反代了,分分钟 IP 被封。。。
lslqtz
2016-07-19 10:15:06 +08:00
@alect 因为我要更换域名而且要公开。。
@Zohar sub_filter_once off;
lslqtz
2016-07-19 10:15:25 +08:00
@crazycen 百度云加速国内节点大法好,反正 IP 提个 ticket 就换~
Tink
2016-07-19 10:34:27 +08:00
强。。。。。

有个模块叫 replace-filter-nginx-module
zanewell
2016-07-19 10:34:28 +08:00
@alect sniproxy 有无好办法防范代理服务器 ip 暴露?
lslqtz
2016-07-19 10:49:38 +08:00
@zanewell 做 CDN 。
zingl
2016-07-19 11:29:30 +08:00
首先,你见过有人反代 YT 成功的么?
其次,反代不成功的 URL 你在页面源码里找得到么?
lslqtz
2016-07-19 12:09:41 +08:00
@zingl 找不到。。
YingJie
2016-07-19 19:32:10 +08:00
题外话:反代不如弄镜像站,
jsteward
2016-07-25 19:25:09 +08:00
小问题:移动端还是会跳到 m.youtube.com

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/293356

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX