惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

www.infosecurity-magazine.com
www.infosecurity-magazine.com
D
DataBreaches.Net
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
F
Full Disclosure
V2EX - 技术
V2EX - 技术
N
News and Events Feed by Topic
Help Net Security
Help Net Security
L
LangChain Blog
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
Google Online Security Blog
Google Online Security Blog
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
B
Blog RSS Feed
N
Netflix TechBlog - Medium
N
News | PayPal Newsroom
TaoSecurity Blog
TaoSecurity Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Vulnerabilities – Threatpost
B
Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
I
Intezer
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
AI
AI
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyberwarzone
Cyberwarzone
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
G
GRAHAM CLULEY
Vercel News
Vercel News
罗磊的独立博客
MyScale Blog
MyScale Blog
Last Week in AI
Last Week in AI
博客园 - 司徒正美
C
CERT Recently Published Vulnerability Notes
GbyAI
GbyAI
Scott Helme
Scott Helme
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Troy Hunt's Blog
A
About on SuperTechFans
P
Privacy International News Feed

WoodenRobot's Blog

Mac OS 系统无法双击使用 Chrome 浏览器打开 HTML 文件 群晖 SSH 公钥免密登录 群晖 Moments 人物识别一键修复解决方案 获取联通友华 PT952G 光猫超级密码和宽带拨号账号密码 去除 iTerm2 下 Tmux 复制模式警告 优化 oh my zsh 启动速度 优酷路由宝 YK-L1c 和 YK-L1 刷入 Breed 不死和 hiboy Padavan 固件 Zoom 直播分享 Awesome pipeline 录像和资料下载 Python 使用 Redis 实现分布式锁 [转]Python 相对导入与绝对导入 Mac 使用 Brew 升级 openssl@1.1 问题 Linux通过源码编译安装 Python3.8 家庭网络漫游指南 修复黑群晖 Moments 1.3.3-0700 版本人物识别不能使用问题 TOTOLINK A3004NS 国行刷入 Breed 不死和 hiboy Padavan 固件 中兴 ZXHN F677V2 光猫改桥接 [转] Python 的 Buffer 机制 群晖 Video Station 支持 DTS 和 eac3 解决方案 浏览器输入 URL 后的历程
Nginx 搭建 Google 镜像站
本文作者: WoodenRobot · 2019-08-26 · via WoodenRobot's Blog

前言

在公司科学上网使用谷歌经常出现很长一段时间访问不了,严重影响工作效率,没办法只能自己搭建一个镜像网站。

正文

环境

  • 机房:搬瓦工
  • 系统:Ubuntu 18.04
1
$ sudo apt install nginx

增加 nginx 配置

/etc/nginx/sites-enabled 文件夹内新增 google.conf 配置文件,配置文件内容为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
server {
server_name www.example.com;

location / {
proxy_pass https://www.google.com/;

proxy_redirect https://www.google.com/ /;
proxy_cookie_domain google.com www.example.com;

proxy_set_header User-Agent $http_user_agent;
proxy_set_header Cookie "PREF=ID=047808f19f6de346:U=0f62f33dd8549d11:FF=2:LD=zh-CN:NW=1:TM=1325338577:LM=1332142444:GM=1:SG=2:S=rE0SyJh2W1IQ-Maw";
# 这里设置cookie,这里是别人给出的一段,必要时请放上适合你自己的cookie
# 设置这个可以避免一些情况下的302跳转,如果google服务器返回302 redirect,那么浏览器被跳转到google自己的域名,那就没的玩了

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

subs_filter http://www.google.com http://www.example.com;
subs_filter https://www.google.com http://www.example.com;
# 这里替换网页中的链接,因为我们的镜像站是http的,所以上面顺便把协议也一起替换了
}
}

注:请手动更改配置中的 www.example.com 为自己的域名地址

载入配置

使用下列命令重新载入配置

1
$ nginx -s reload

添加 DNS 解析记录

将自己的域名添加一条指向该台服务器 IP 的 DNS 解析记录,访问域名即可实现访问谷歌。

增加 Basic Auth 认证

如果不想自己的谷歌镜像被别人乱用,可以增加 Basic Auth 来限制其他人使用。

生成密码

使用下列命令生成密码:

1
$ printf "your_username:$(openssl passwd -crypt your_password)\n" >> /etc/nginx/conf.d/passwd

配置 Nginx

用 vim 修改刚刚的配置文件

1
$ vim /etc/nginx/sites-enabled/google.conf

增加下列内容

1
2
3
4
5
6
7
8
...

location / {
auth_basic "Hello World";
auth_basic_user_file conf.d/passwd;

proxy_pass https://www.google.com/;
...

然后 nginx -s reload 重启 Nginx 生效。

参考

  1. Nginx 搭建 Google 镜像站
  2. 为 Nginx 添加 HTTP 基本认证(HTTP Basic Authentication)