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

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

Rat's Blog - lnmp

宝塔面板LNMP开启Brotli压缩,可提高网站加载速度 - Rat's Blog 使用OneinStack搭建网站LNMP环境,并配置WAF防火墙防CC攻击 - Rat's Blog LNMP中一些隐藏的安装脚本及目录详解 - Rat's Blog LNMP一键安装包V1.5测试版已发布 - Rat's Blog LNMP环境下WordPress后台只显示一个主题预览的解决方法 - Rat's Blog LNMP环境下php-fpm启动失败的解决方法 - Rat's Blog LNMP环境下使用CDN后获取访客真实IP的方法 - Rat's Blog lnmp1.4安装及部署typecho或其它博客教程 - Rat's Blog LNMP一键安装后Nginx不能自启的解决方法 - Rat's Blog
LNMP环境下,利用Nginx反代Google网站的方法 - Rat's Blog
博主: Rat's · 2017-12-12 · via Rat's Blog - lnmp

说明:反代的方法有很多,之所以选择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,可以在文章下面评论留言。