5月52022
nginx任意反向代理配置(支持github,ip138,google) 这个是纯NGINX的任意反向代理
server { listen 80; server_name localhost; #改成自己的域名 root "/home/wwwroot/default"; #改自己的服务器目录 set $custom_PATH /HostLocMJJ; set $custom_host "https://www.baidu.com"; set $custom_host3 "/"; set $custom_host5 "/"; if ($request_uri ~* ^\/(.+)\/((http|https)://(www.)?([\w-]+(\.)?)+)(.*?)$) { set $custom_host $2; set $custom_host3 $7; } if ($custom_host3 = ""){ set $custom_host3 "/"; } if ($custom_host3 = " "){ set $custom_host3 "/"; } if ($request_uri ~* ^\/(.+)\/((http|https)://(www.)?([\w-]+(\.)?)+)(.+)\?(.+)$) { set $custom_host3 $7; } if ($request_uri ~* ^\/(.+)\/((http|https)://)((www.)?(\w+(\.)?)+)$) { return 301 $custom_PATH/$custom_host/; } set $custom_host2 "www.baidu.com"; if ($custom_host ~* ^((http|https)://)((www.)?([\w-]+(\.)?)+)$) { set $custom_host2 $3; set $custom_host5 $1; } set $referer $custom_host; if ($http_referer ~* ^((http|https)://)(.*?)\/(.+)\/((http|https)://)(.*?)$) { set $referer $5$7; } set $current "http://"; if ($scheme = https) { set $current "https://"; } proxy_hide_header content-security-policy; location /HostLocMJJ/ { # proxy_connect_timeout 100s; # add_header Content-Security-Policy "default-src 'self' https://$host http://$host 'unsafe-inline' 'unsafe-eval' blob: data: ;"; # 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_ssl_server_name on; proxy_set_header X-Forwarded-Proto $ishttp; proxy_set_header Host $custom_host2; proxy_cache_key $host$uri$is_args$args; proxy_headers_hash_max_size 512; proxy_pass_header Server; proxy_headers_hash_bucket_size 128; proxy_buffer_size 64k; proxy_buffers 32 64k; proxy_busy_buffers_size 128k; proxy_set_header Cookie $http_cookie; proxy_cache_methods GET; proxy_cache_methods POST; proxy_cache_methods HEAD; proxy_redirect $upstream_http_location "$current$host$custom_PATH/$upstream_http_location"; proxy_set_header Referer $referer; proxy_set_header User-Agent $http_user_agent; # 防止谷歌返回压缩的内容,因为压缩的内容无法替换字符串 proxy_set_header Accept-Encoding ""; proxy_connect_timeout 15000; proxy_send_timeout 15000; proxy_read_timeout 15000; proxy_cache_valid 200 304 301 1s; add_header MJJCDN-Cache "$upstream_cache_status"; # proxy_temp_file_write_size 512000k; resolver 1.1.1.1; #改为自己想要的DNS proxy_set_header Accept-Encoding ""; sub_filter_types text/plain text/javascript text/xml text/css application/x-javascript application/xml; sub_filter_once off; proxy_temp_file_write_size 512000k; sub_filter "url(http" "url($current$host$custom_PATH/http"; sub_filter "<head" '<base href="$current$host$custom_PATH/$custom_host/" /><head'; sub_filter '\'https://' '\'$current$host$custom_PATH/https://'; sub_filter '\'http://' '\'$current$host$custom_PATH/https://'; sub_filter '\"https://' '\"$current$host$custom_PATH/https://'; sub_filter '\"http://' '\"$current$host$custom_PATH/https://'; sub_filter "=\"//" '="$current$host$custom_PATH/https://'; sub_filter '="/' '="$current$host$custom_PATH/$custom_host/'; sub_filter "='//" "='$current$host$custom_PATH/https://"; sub_filter "='/" "='$current$host$custom_PATH/$custom_host/"; sub_filter '="/search' '"search'; sub_filter '"/images' '"images'; sub_filter ', /images' ', images'; sub_filter 'integrity' ', kkkk'; sub_filter '../' '$current$host$custom_PATH/$custom_host/../'; sub_filter "'http://$custom_host2" "'$current$host$custom_PATH/$custom_host"; sub_filter "'https://$custom_host2" "'$current$host$custom_PATH/$custom_host"; sub_filter "\"http://$custom_host2" "\"$current$host$custom_PATH/$custom_host"; sub_filter "\"https://$custom_host2" "\"$current$host$custom_PATH/$custom_host"; if ($request_uri ~* ^\/(.+)\/((http|https)://(www.)?([\w-]+(\.)?)+)(.*?)$) { proxy_pass $custom_host$7$is_args$query_string; } # # set $request_uri "qqqq"; # add_header Content-Type "text/plain;charset=utf-8"; # return 200 "Your IP Address:$referer</br>$http_referer"; } location / { add_header Content-Type "text/plain;charset=utf-8"; return 200 "这是个正经网站"; } }
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!