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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

Rat's Blog - Nginx

使用Nginx反向代理,自建CDN加速节点 - Rat's Blog LNMP环境下,利用Nginx反代Google网站的方法 - Rat's Blog Nginx环境下对部分网站做防盗链设置及外链的跳转 - Rat's Blog CentOS 7安装配置Nginx 1.10、PHP 5.6、MySQL 5.7教程 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
利用Nginx反向代理来简单镜像HTTP(S)网站的方法 - Rat's Blog
博主: Rat's · 2017-08-28 · via Rat's Blog - Nginx

说明:之前发过一个反代教程:Linux Centos下Nginx反代教程,现在发个Debian下反代HTTP(S)网站的教程。

安装nginx

系统要求:Debian 7

echo "deb http://packages.dotdeb.org wheezy all" >> /etc/apt/sources.list
apt-get update
apt-get install nginx
# 安装会提示输入两次 Y 来继续安装。

安装完毕之后输入nginx -v ,查看nginx的版本,确定是否安装完成。

修改配置文件

找到下面这个文件,然后修改。

vi /etc/nginx/sites-available/default

按照下面的示例修改完毕后就重启Nginx

service nginx restart

然后访问你的域名看一看是否成功镜像,需要注意的一点是,如果被镜像的网站设置了防盗链,那么静态文件(js/css/图片)可能无法显示,这就没办法了。

1、HTTP示例
一般情况下只需要更改这几个参数。

server_name 你的域名;
sub_filter 欲被镜像的域名 你的域名;
proxy_set_header Referer http://欲被镜像的域名
proxy_set_header Host 欲被镜像的域名
proxy_pass http://欲被镜像的域名

以下示例是以go.doubi.date镜像www.baidu.com为例。自行替换其中的参数:

第二段是屏蔽搜索引擎收录,比如镜像自己的网站,如果不屏蔽会导致收录流失。

server
    {
        listen 80;
        server_name go.doubi.date;
        
        if ($http_user_agent ~* (baiduspider|360spider|haosouspider|googlebot|soso|bing|sogou|yahoo|sohu-search|yodao|YoudaoBot|robozilla|msnbot|MJ12bot|NHN|Twiceler)) {
        return  403;
        }
  
        location / {
        sub_filter www.baidu.com go.doubi.date;
        sub_filter_once off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Referer http://www.baidu.com
        proxy_set_header Host www.baidu.com
        proxy_pass http://www.baidu.com
        proxy_set_header Accept-Encoding "";
        }
}

2、HTTPS示例
当你要镜像的网站不开放HTTP或者强制HTTPS的时候,你就需要加上SSL来转成HTTPS了。
假设SSL证书文件位置是:/root/ssl.crt
假设SSL密匙文件位置是:/root/ssl.key
第二段的301码是,强制走HTTPS,如果不需要可以去掉。
第三段是屏蔽搜索引擎收录,比如镜像自己的网站,如果不屏蔽会导致收录流失。
同时下面这两个选项的记得把http://改成https://

proxy_set_header Referer https://www.baidu.com
proxy_pass https://www.baidu.com
server
    {
        listen 80;
        listen 443 ssl;
        ssl on;
        ssl_certificate /root/ssl.crt;
        ssl_certificate_key /root/ssl.key;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout  10m;
        server_name go.doubi.date;
        add_header Strict-Transport-Security "max-age=31536000";
        
        if ( $scheme = http ){
            return 301 https://$server_name$request_uri;
        }
        
        if ($http_user_agent ~* (baiduspider|360spider|haosouspider|googlebot|soso|bing|sogou|yahoo|sohu-search|yodao|YoudaoBot|robozilla|msnbot|MJ12bot|NHN|Twiceler)) {
        return  403;
        }
  
        location / {
        sub_filter www.baidu.com go.doubi.date;
        sub_filter_once off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Referer https://www.baidu.com
        proxy_set_header Host www.baidu.com
        proxy_pass https://www.baidu.com
        proxy_set_header Accept-Encoding "";
        }
}

原文地址:https://doub.io/wlzy-3/


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

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

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