乐云主机笔记

  • 首页
  • 主机优惠
  • 学习记录
  • 新手教程
  • 自用主机
  • 资源下载
  • 网赚项目
  • 其他
  • pingtest

  1. 首页
  2. 脚本源码
  3. 正文

[转]一个nginx任意反向代理配置.(已更新,支持IP138,google)

2022年5月3日 325点热度 0人点赞 0条评论

以下转自LOC论坛


之前有人分享过php的,但效率有点低。
这个是纯NGINX的任意反向代理
使用访问地址示例:
http://127.0.0.1/https://hostloc.com

github项目链接:https://github.com/linwoodpendleton/nginx_proxy_conf

注:http://127.0.0.1/https://hostloc.com
网址后面那个是反代地址。
不用改代码输入
http://127.0.0.1/https://www.163.com 就反代163了。


1:24更新:
支持反代CF github.com
测试:
https://www.php8.ltd/http://news.baidu.com/
https://www.php8.ltd/https://github.com/ElderDrivers/EdXposed

5.4 10:32更新
支持中文维基
301跟随,有301不会再跳出

5.4 15:51更新
支持自定义路径 替换HostLocMJJ 为你自己的路径即可 有两处
修复了一些已知问题

5.4 10:32更新
支持中文维基
301跟随,有301不会再跳出

5.4 15:51更新
支持自定义路径 替换HostLocMJJ 为你自己的路径即可 有两处
修复了一些已知问题

5.4 22:54更新
修复301BUG和一些已知问题。

5.5 18:16 更新
解决套CF 后还是能获取客户端IP
解决因正则导致的500错误

5.5 22:30更新

修复git clone 无法使用
修复一些已知问题

5.6 21:46更新

修复目标站开启强制gzip 无法替换文本问题   set $unopengzip 0; #对于强制开启压缩的网站开启替换 0 关, 1 开 影响效率
增加一个伪装站。 修改**即可

代码如下:

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/$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 223.5.5.5; #改为自己想要的DNS
            proxy_set_header Accept-Encoding "";
            sub_filter_types text/plain   text/xml text/css  application/xml;

            sub_filter_once off;
            proxy_temp_file_write_size 512000k;
            sub_filter "<head" '<base href="$current$host$custom_PATH/$custom_host/" />\n<head';
            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";
            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 "这是个正经网站";
        }

}

 

标签: 暂无
最后更新:2022年5月6日

letvps

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

分类
  • 主机优惠
  • 其他
  • 域名优惠
  • 学习记录
  • 新手教程
  • 网赚项目
  • 脚本源码
  • 自用主机
  • 资源下载
书签
  • AdvinServers.com
  • 猫云云计算

COPYRIGHT © 2021 Letcloud.cn. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

粤ICP备15031609号-3