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

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

Rat's Blog - Google

利用Aria2+AriaNg+H5ai+Google Drive建立离线BT下载/在线播放/无限空间网盘 - Rat's Blog 使用Google Drive File Stream后,C盘没空间/爆满的解决方法 - Rat's Blog Mac系统下挂载Google Drive网盘为本地硬盘使用 - Rat's Blog 分享几款强大的类似Google搜索的搜索引擎 - Rat's Blog 分享几个好用的Google Hosts - Rat's Blog 可以直接获取并下载Google Play APK的镜像站 - Rat's Blog
LNMP环境下,利用Nginx反代Google网站的方法 - Rat's Blog
博主: Rat's · 2017-12-12 · via Rat's Blog - Google

说明:反代的方法有很多,之所以选择lnmp的原因是方便,因为利用Nginx反代网站需要--with-http_sub_module拓展,而军哥的lnmp已经自动添加了,1.4版本的lnmp也可以自动签发SSL证书,不需要我们额外来申请,所以挺方便的,基本只要直接编辑配置文件即可!这里说下方法。

方法

本方法主要以反代Google为主,想反代其它网站的可以照葫芦画瓢,或者参考:利用Nginx反代来简单镜像HTTP(S)网站的方法,照搬配置文件就可以了。

首先得添加域名及自动签发SSL证书。然后编辑域名配置文件/usr/local/nginx/conf/vhost/your.com.conf

server {
        listen 443;
        server_name 你的域名;
        #为了安全考虑(例如IP被Q),强烈建议使用HTTPS
        ssl on;
        ssl_protocols TLSv1.2;
        ssl_certificate ~/站点证书
        ssl_certificate_key ~/站点证书密钥
        location / {
            proxy_pass                          https://www.google.com;
            #把返回的302重定向的域名替换成你的。这里关闭
            proxy_redirect                      off;
            #替换指定字符串
            sub_filter                          www.google.com 你的域名;
            #字符串只进行一次替换,即只替换第一个被匹配的字符串。这里关闭。
            sub_filter_once                     off;
            #指定头部:
            proxy_set_header  Host              "www.google.com";
            proxy_set_header  Referer           $http_referer;
            proxy_set_header  X-Real-IP         $remote_addr;
            proxy_set_header  User-Agent        $http_user_agent;
            proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header  X-Forwarded-Proto https;
            #防止谷歌返回压缩的内容,因为压缩的内容无法替换字符串
            proxy_set_header  Accept-Encoding   "";
            proxy_set_header  Accept-Language   "zh-CN";
            #把cookie的作用域替换成你的域名
            proxy_cookie_domain                 www.google.com 你的域名;
            #传固定的cookie给谷歌,是为了禁止即时搜索,因为开启即时搜索无法替换内容
            proxy_set_header  Cookie            "PREF=ID=047808f19f6de346:U=0f62f33dd8549d11:FF=2:LD=en-US:NW=1:TM=1325338577:LM=1332142444:GM=1:SG=2:S=rE0SyJh2W1IQ-Maw";
            #启用proxy_cache缓存
            proxy_cache                 proxycache;
            proxy_cache_valid           304 2h;
            proxy_cache_valid           403 444 2h;
            proxy_cache_valid           404 2h;
            proxy_cache_valid           500 502 2h;
            proxy_cache_use_stale       invalid_header http_404 http_500 http_502;
            proxy_cache_lock            on;
            proxy_cache_lock_timeout    5s;
        }
}

这里启用了proxy_cache这个缓存。一般lnmp已经编译了proxy_cache,需要我们编辑下nginx.conf文件才能使用。

#在http里面添加如下代码即可
http {
    proxy_cache_path  /home/cache levels=1:2 keys_zone=proxycache:60m max_size=120m inactive=2h use_temp_path=on;
    proxy_temp_path   /home/temp;
    proxy_cache_key   $host$uri;
}

注意:记得将配置文件里的www.google.com替换成你VPS所在国家的Google官网,不然可能会反代不成功,只出现域名跳转的情况。

之前是监控的443端口,然后再做域名的301跳转,将80端口的http跳转到https,编辑conf配置文件增加以下代码。

server {                            
    listen 80;                            
    server_name moerats.com;
    return 301 https://www.moerats.com$request_uri;
     }

最后重启Nginx即可。

lnmp nginx restart

配置参考:Nginx反代Google(进阶篇


版权声明:本文为原创文章,版权归 Rat's Blog 所有,转载请注明出处!

本文链接:https://www.moerats.com/archives/445/

如教程需要更新,或者相关链接出现404,可以在文章下面评论留言。