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

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
V
Vulnerabilities – Threatpost
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
C
Cisco Blogs
A
Arctic Wolf
月光博客
月光博客
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
量子位
小众软件
小众软件
Latest news
Latest news
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
N
Netflix TechBlog - Medium
K
Kaspersky official blog
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
Y
Y Combinator Blog
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
S
Schneier on Security
D
Docker
Scott Helme
Scott Helme
MyScale Blog
MyScale Blog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
GbyAI
GbyAI
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
J
Java Code Geeks
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tenable Blog
B
Blog
Know Your Adversary
Know Your Adversary
IT之家
IT之家

Rat's Blog - Nginx

使用Nginx反向代理,自建CDN加速节点 - Rat's Blog Nginx环境下对部分网站做防盗链设置及外链的跳转 - Rat's Blog CentOS 7安装配置Nginx 1.10、PHP 5.6、MySQL 5.7教程 利用Nginx反向代理来简单镜像HTTP(S)网站的方法 - Rat's Blog LNMP环境下使用CDN后获取访客真实IP的方法 - Rat's Blog Nginx给网站添加用户认证配置( Basic HTTP authentication) - Rat's Blog Nginx环境使用auth_basic密码保护wordpress后台登录界面 - Rat's Blog Nginx环境开启ssl后强制https 301全部指向www的方法 - Rat's Blog 防止Linux VPS主机Nginx环境根目录被解析的方法 - Rat's Blog
LNMP环境下,利用Nginx反代Google网站的方法 - Rat's Blog
博主: Rat's · 2017-12-12 · via Rat's Blog - Nginx

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