利用Nginx反向代理网站的方法

  • A+
所属分类:WEB

由于手里的域名太多没用,老是想怎么给他利用起来。后来想到可以反向代理一些其他有用的网站,做个说明方便以后常使用:

首先是安装nginx,我一直是使用的军哥的lnmp 里边自带nginx,自己在网站搜LNMP里边就有怎么安装,这里就不阐述了,

 

# 下面这段代码才是 HTTP 完整示例配置文件,注意使用时修改里面的默认域名等信息。
server
	{
		listen 80;
		server_name www.vjsun.com;
		
		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.google.com www.vjsun.com;
		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.google.com;
		proxy_set_header Host www.google.com;
		proxy_pass http://www.google.com;
		proxy_set_header Accept-Encoding "";
		}
}

说明解释:

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

 

# 下面这段代码才是 HTTPS 完整示例配置文件,注意使用时修改里面的默认域名等信息。
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 www.vjsun.com;
		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.google.com www.vjsun.com;
		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.google.com;
		proxy_set_header Host www.google.com;
		proxy_pass https://www.google.com;
		proxy_set_header Accept-Encoding "";
		}
}

 

 

weinxin
我的QQ群
这是我的QQ群扫一扫

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: