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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Security Latest
Security Latest
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
S
Secure Thoughts
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
D
DataBreaches.Net
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
V
V2EX
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tenable Blog
T
Threat Research - Cisco Blogs
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
F
Full Disclosure
H
Help Net Security
博客园 - Franky
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
O
OpenAI News
S
Securelist

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,可以在文章下面评论留言。