nginx反代任意网站配置代码文件。关键时候可以用于下载文件,或者访问用途。
不是很懂下面代码,好像反代失败会默认反代百度网站。
懂的自己研究下吧。
server {
listen 80;
server_name myname host; #改成自己的域名
root "/home/wwwroot/default"; #改自己的服务器目录
set $custom_host "https://www.baidu.com";
set $custom_host3 "/";
set $custom_host5 "/";
if ($request_uri ~* ^\/((http|https)://(www.)?(\w+(\.)?)+)(.*?)$) {
set $custom_host $1;
set $custom_host3 $6;
}
if ($custom_host3 = ""){
set $custom_host3 "/";
}
if ($custom_host3 = " "){
set $custom_host3 "/";
}
if ($request_uri ~* ^\/((http|https)://(www.)?(\w+(\.)?)+)(.+)\?(.+)$) {
set $custom_host3 $6;
}
set $custom_host2 "www.baidu.com";
if ($request_uri ~* ^\/((http|https)://)((www.)?(\w+(\.)?)+)(.*?)$) {
set $custom_host2 $3;
set $custom_host5 $1;
}
if ($request_uri ~* ^\/((http|https)://)((www.)?(\w+(\.)?)+)$) {
set $custom_host2 $3;
set $custom_host5 $1;
}
set $current "http://";
if ($scheme = https) {
set $current "https://";
}
location / {
rewrite /(.*)$ $custom_host3 break;
proxy_connect_timeout 100s;
proxy_set_header x-forwarded-for $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
set $ishttp "http";
if ($custom_host5 = https://) {
set $ishttp https;
}
proxy_set_header X-Forwarded-Proto $ishttp;
proxy_set_header Host $custom_host2;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Cookie $http_cookie;
proxy_cache_methods GET;
proxy_cache_methods POST;
proxy_cache_methods HEAD;
proxy_set_header Accept-Encoding "";
#proxy_connect_timeout 15000;
proxy_send_timeout 15000;
proxy_read_timeout 15000;
sub_filter_types *;
proxy_cache_valid 200 304 301 1s;
add_header TJCDN-Cache "$upstream_cache_status";
proxy_temp_file_write_size 512000k;
resolver 8.8.8.8; #改为自己想要的DNS
proxy_set_header Accept-Encoding "";
sub_filter "<title" '<base href="$current$host/$custom_host/" />\n<title';
sub_filter "\"/" '"';
sub_filter "http://$custom_host2" "$current$host/$custom_host";
sub_filter "https://$custom_host2" "$current$host/$custom_host";
sub_filter_once off;
proxy_pass $custom_host;
# # set $request_uri "qqqq";
# add_header Content-Type "text/plain;charset=utf-8";
# return 200 "Your IP Address:$custom_host2</br>$request_uri";
}
}
代码贴在网站配置里面。
来自loc mjj创作 观看热闹地址
还是贴一个配置文件压缩包吧
链接: https://pan.baidu.com/s/1-tNIaO-UErhsaXjMvCNQsQ?pwd=cg96 提取码: cg96
复制这段内容后打开百度网盘手机App,操作更方便哦
--来自百度网盘超级会员v1的分享