Skip to content

Instantly share code, notes, and snippets.

@shellexy
Created June 6, 2012 14:57
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save shellexy/2882386 to your computer and use it in GitHub Desktop.
Save shellexy/2882386 to your computer and use it in GitHub Desktop.
nginx 反向代理推特官网移动版给 Chrome Lite/Mobile Safari 使用
# /etc/nginx/sites-available/fanfou.shellex.info
# 这儿假设的域名是 fanfou.shellex.info
# 请替换为实际的域名
server {
resolver 8.8.8.8;
listen 443;
server_name fanfou.shellex.info;
ssl on;
#ssl_certificate /etc/nginx/ssl/server.crt;
#ssl_certificate_key /etc/nginx/ssl/server.key;
if ($http_user_agent !~ "Chrome|Safari|Opera") { return 404; }
access_log /var/log/nginx/fanfou.access.log;
location / {
gzip on;
proxy_set_header Accept-Encoding "";
#proxy_hide_header User-Agent;
#proxy_set_header User-Agent "Mozilla/5.0 (iPhone; U; Linux; zh-cn) AppleWebKit/532+ (KHTML, like Gecko) Version/3.0 Chrome Mobile/1A538b Safari/419.3";
proxy_redirect https://mobile.twitter.com/ https://fanfou.shellex.info/;
proxy_pass https://mobile.twitter.com$request_uri;
sub_filter mobile.twitter.com fanfou.shellex.info;
sub_filter_once off;
}
}
server {
listen 80;
server_name fanfou.shellex.info;
if ($http_user_agent !~ "Chrome|Safari|Opera") { return 404; }
rewrite ^/(.*) https://$host$request_uri permanent;
}
@elvisw
Copy link

elvisw commented Jun 7, 2012

咱不用nginx,哎

@shellexy
Copy link
Author

shellexy commented Jun 7, 2012

这个在 Android 或 iPhone 手机浏览器下打开是全功能的 iPhone 版页面,
但是桌面 Chrome 下打开却默认是基本版页面,少了好多东西。

桌面 Chrome 可以修改 UA(在 Chrome 按 F12 打开开发者工具,点击右下角的齿轮打开 Settings 面板,可以看到 User Agent 选项)

去掉 nginx 代理规则里关于 UA 的注释可以部分显示为 iPhone 移动版内容,
但是由于 javascript window.navigator 对不上,页面无法使用。

可能得在页面里插入 js 来篡改 window.navigator,

不过多条替换规则得用第三方 nginx 模块不太方便。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment