其实很简单,使用nginx的反向代理就可以解决
1.建立一个站点A用于做代理
- 将要访问的目标站点B以get参数传入A站点的url
3.nginx接收参数并重定向到B站点
以下是nginx配置
#PROXY-START/
location ~* \.(php|jsp|cgi|asp|aspx)$
{
proxy_pass http://www.baidu.com;
proxy_set_header Host www.baidu.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
}
location /
{
proxy_pass http://www.baidu.com;
proxy_set_header Host www.baidu.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
proxy_ignore_headers Set-Cookie Cache-Control expires;
proxy_cache cache_one;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 304 301 302 1m;
expires 12h;
}
resolver 8.8.8.8; # 这句要加上 要不然会报403
location ~/video {
if ($query_string ~* ^(.*)url=(.*)$){ # 接收url参数
set $videoUrl $2;
proxy_pass $videoUrl;
}
}
#PROXY-END/
小伙伴们自行配置测试吧