傅令江的光影色彩世界
留住记忆的点滴
  • 首页
  • 文学
    • 诗词鉴赏
    • 美文共读
    • 原创
  • 编程
    • php
    • asp
    • .net
    • VB
    • C/C++
    • 易语言
    • js
    • 其他
    • 逆向
  • 运维
    • windows
    • linux
  • 光影色彩
    • 电影
    • 音乐
  • 科技
    • 互联网
    • 手机
  • 生活
    • 情感
  • 微语
5月52022

nginx任意反向代理配置(支持github,ip138,google) 这个是纯NGINX的任意反向代理

作者:傅令江   发布:2022-5-5 15:32   分类:linux   阅读:3270次   评论:0条  
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 "这是个正经网站";
        }


}



本文固定链接: https://www.fulingjiang.cn/237.html

blogger
该日志由 傅令江 于2022-5-5 15:32 Thursday发表在 linux 分类下。
版权所有:《傅令江的光影色彩世界》 → 《nginx任意反向代理配置(支持github,ip138,google) 这个是纯NGINX的任意反向代理》;
除特别标注,本博客所有文章均为原创. 互联分享,尊重版权,转载请以链接形式标明本文地址;
本文标签:
上一篇::wget 读取file中的url 批量下载
下一篇:Nginx 反向代理任意请求的域名

热门文章

  • 兄弟二周年祭

相关文章

  • 405报错是什么原因_状态码405是什么错误
  • 用Piranha来实现WEB的负载均衡
  • Unix、Linux下常用监控和管理命令工具
  • SVN在另类环境中实现自动提交的方法,nfs共享的方法
  • Nginx/LVS/HAProxy负载均衡软件的优缺点详解
取消回复

发表评论

亲,头像对么?

提交中,请稍候……


木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!


  • 日历

  • 存档

    • 2024年10月(1)
    • 2023年2月(1)
    • 2022年11月(1)
    • 2022年10月(10)
    • 2022年9月(13)
    • 2022年8月(2)
    • 2022年7月(14)
    • 2022年6月(2)
    • 2022年5月(8)
    • 2022年4月(7)
    • 2022年3月(13)
    • 2022年2月(2)
    • 2022年1月(9)
    • 2021年12月(2)
    • 2021年11月(4)
    • 2021年10月(2)
    • 2021年9月(6)
    • 2021年7月(4)
    • 2021年6月(3)
    • 2021年5月(3)
    • 2021年4月(11)
    • 2021年3月(13)
    • 2021年2月(2)
    • 2021年1月(1)
    • 2020年12月(1)
    • 2020年4月(5)
    • 2019年9月(1)
    • 2019年8月(1)
    • 2019年5月(3)
    • 2018年3月(1)
    • 2017年10月(1)
    • 2016年7月(1)
    • 2016年4月(1)
    • 2015年12月(1)
    • 2015年11月(3)
    • 2015年9月(1)
    • 2015年8月(10)
    • 2015年7月(1)
    • 2015年6月(1)
    • 2015年4月(1)
    • 2015年3月(3)
    • 2015年2月(8)
    • 2015年1月(4)
    • 2014年12月(1)
    • 2014年11月(27)
    • 2014年10月(13)
    • 2014年9月(14)
    • 2014年8月(26)
    • 2014年7月(21)
  • 最新评论

    • 令狐江:
      喜欢这首歌是因为可以引起共鸣!
  • 链接

    • 演讲稿网
    • Recollect
    • 演讲稿
    • 祁阳人生活网
    • 我爱演讲稿网
  • 搜索

  • 标签

      函数 自定义方法 SEO 分页 分页函数 分页方法 nginx重新的一些规则
  • 分类

    • 文学(0)
    • 编程(0)
    • 运维(0)
    • 光影色彩(0)
    • 科技(0)
    • 生活(0)
    • 诗词鉴赏(3)
    • 美文共读(1)
    • 原创(10)
    • php(111)
    • asp(1)
    • .net(0)
    • VB(0)
    • C/C++(0)
    • 易语言(0)
    • js(8)
    • 其他(9)
    • 逆向(2)
    • windows(11)
    • linux(121)
    • 电影(0)
    • 音乐(1)
    • 互联网(4)
    • 手机(0)
    • 情感(2)
  • 最新文章热门文章随机文章

    • 兄弟二周年祭
    • openai给的ionCube 解密代码,应该是老版本可以这样
    • WordPress – 5秒盾防CC(PHP通用代码)
    • 我高中最好的朋友今天猝死了-伤心得不行
    • Linux系统中 systemd-journaldCPU占用异常的解决方法
    • SVN Skipped 'xxx' -- Node remains in conflict 错误的解决办法
    • 解决Linux读写nfs共享盘速度慢的问题
    • php 获取302跳转后的地址
    • 让vsftp显示隐藏文件的办法,比如显示 .htaccess
    • 添加自签名https证书到centos系统信任的问题
    • php采集
    • 监控memcache服务端口
    • js判断手机访问跳转到手机站
    • php判断客户端是否为手机
    • centos5一个不错的yum源
Copyright © 2001-2025 傅令江的光影色彩世界. Powered by www.fulingjiang.cn ICP备案:京ICP备14015190号-5