用 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;
}
}
11369 次点击
所在节点    问与答
21 条回复
bilibiliQQ
2018-02-11 17:18:08 +08:00
试试这个
http://2tube。js。org

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

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

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

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

© 2021 V2EX