Nginx反向代理GitHub

根据https://github.com/linwoodpendleton/nginx_proxy_conf

这位大佬的配置文件修改的,可以直接用在反向代理github

使用方法:

安装配置nginx

将文件上传到nginx配置目下的conf.d目录

然后将两处example.com 改成你自己的域名,并在pem和key的地方替换上你自己的网站证书即可

server
    {
        listen 443 ssl http2;
        server_name example.com;	#你的域名
	ssl_certificate github.pem;	#你的 RSA pem
	ssl_certificate_key github.key;	#你的 RSA pem
	if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") {
		return 403;
	}

        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers on;
        ssl_ciphers "TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5";
        ssl_session_cache builtin:1000 shared:SSL:10m;

set $custom_PATH /host;
        set $custom_host "pass";
        set $custom_host3 "/";
        set $custom_host5 "/";
        set $unopengzip 0; #对于强制开启压缩的网站开启替换 0 关, 1 开
        if ($request_uri ~* ^\/(.+)\/((http|https)://(www.)?([\w-]+(\.)?)+)(.*?)$) {
            set $custom_host $2;
            set $custom_host3 $7;
        }


        #允许域名 域名白名单
        set $banDomain 1;
        #if ($custom_host = "https://github.goblog.top/host/https://github.com") {
        #    set $banDomain 0;
        #}
	if ( $custom_host ~ (^https://github\.com|\.github\.com|^https://githubassets\.com|\.githubassets\.com|^https://githubusercontent\.com|\.githubusercontent\.com)$ ) {
	     set $banDomain 0;
	}


        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 ~* ^\/(.+)\/((ht|f)tps?):\/\/([\w\-]+(\.[\w\-]+)*)$) {
            return 301 $custom_PATH/$custom_host/;
        }
        set $custom_host2 "www.baidu.com";
        set $custom_host8 "www.baidu.com";
        if ($custom_host ~* ^((http|https)://)((www.)?([\w-]+(\.)?)+)$) {
            set $custom_host8 $3;
            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 "https://github.goblog.top/host/https://";
        if ($scheme = https) {
            set $current "https://github.goblog.top/host/https://";
        }
        set $referer2 "";
        if ($referer ~* ^((http|https)://(www.)?([\w-]+(\.)?)+)(.*?)$) {
            set $referer2 $1;
        }
        set $root_domain ".$myroot_domain";
        set $myroot_domain ".$myroot_domain";
        if ($referer2 ~* (?:\w+\.)*?(\w*\.(.+))[\\\/]*) {
            set $root_domain $2;
        }
        if ($host ~* (?:\w+\.)*?(\w*\.(.+))[\\\/]*) {
            set $myroot_domain $2;
        }

        if ($root_domain = ".$myroot_domain"){
            set $root_domain "${custom_host2}";
        }
        if ($host ~* "(((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?))") {
            set $myroot_domain $host;
        }
        add_header X-Frame-Options $myroot_domain;
        proxy_hide_header X-Frame-Options;
        proxy_hide_header content-security-policy;


        location /host/ {
            if ($banDomain = 1) {
                return 404  ;
            }
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

                add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain charset=UTF-8';
                add_header 'Content-Length' 0;
                return 204;
            }
            if ($request_method = 'POST') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
            }
            if ($request_method = 'GET') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
            }
            proxy_set_header x-forwarded-for "";
            proxy_set_header X-Real-IP "";
            proxy_set_header X-Forwarded-For "";
            proxy_set_header cf-connecting-ip "";
            proxy_set_header True-Client-IP "";
            set $ishttp "http";
            if ($custom_host5 = https://) {
                set $ishttp "https";
            }
            proxy_ssl_server_name on;
            proxy_set_header X-Forwarded-Proto $ishttp;
            add_header Proxy-Cache2 $root_domain;


            if ($unopengzip = 1) {
                set $custom_host2 $host;
            }
            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";
            if ($unopengzip = 1) {
                set $referer $http_referer;
            }
            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_set_header Upgrade   $http_upgrade;
            proxy_cookie_domain $root_domain $myroot_domain;
            proxy_cookie_domain $custom_host8 $myroot_domain;
            proxy_cookie_path ~\/(.*) $custom_PATH/$custom_host/$1;
            proxy_max_temp_file_size 10m;
            proxy_set_header Connection "upgrade";
            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
            sub_filter_types text/plain  text/javascript text/xml text/css application/x-javascript application/xml application/javascript application/json;

            sub_filter_once off;
            proxy_temp_file_write_size 512000k;
            sub_filter '".$root_domain' '".$myroot_domain';
            sub_filter '"$root_domain' '"$myroot_domain';
            sub_filter "url(https://github.goblog.top/host/http" "url($current$host$custom_PATH/http";
            set $head  '<base href=\'$current$host$custom_PATH/$custom_host/\' /><base href='https://github.goblog.top/host/https://raw.githubusercontent.com/' /><head';
            set $html2 'M('<html>';
            set $html3 'M('<html>';
            if ($custom_host = "https://github.goblog.top/host/https://www.gstatic.com") {
                set $head  '<base href=\"$current$host$custom_PATH/$custom_host/\" /><base href='https://github.goblog.top/host/https://raw.githubusercontent.com/' /><head';
                set $html2 "M(\"<html>";
                set $html3  "<base href='https://github.goblog.top/host/https://raw.githubusercontent.com/' /><head>\"";
            }
            if ($referer ~ "www\.google\.com") {
                set $head  '<base href=\"$current$host$custom_PATH/$custom_host/\" /><base href='https://github.goblog.top/host/https://raw.githubusercontent.com/' /><head';
            }
            if ($request_uri ~ "accounts\.google\.com") {
                set $head  '<base href=\"$current$host$custom_PATH/$custom_host/\" /><base href='https://github.goblog.top/host/https://raw.githubusercontent.com/' /><head';
            }
            if ($request_uri ~ "www\.google\.com") {
                set $head  '<base href=\"$current$host$custom_PATH/$custom_host/\" /><base href='https://github.goblog.top/host/https://raw.githubusercontent.com/' /><head';
            }
            sub_filter  $html2 "M('<html>";
            sub_filter  $html3 "<base href='https://github.goblog.top/host/https://raw.githubusercontent.com/' /><head>\'";
            sub_filter "<base href='https://github.goblog.top/host/https://raw.githubusercontent.com/' /><head" $head;
            sub_filter '\'https://github.goblog.top/host/https://' '\'$current$host$custom_PATH/https://';
            sub_filter '\'https://github.goblog.top/host/https://' '\'$current$host$custom_PATH/https://';
            sub_filter '\"https://github.goblog.top/host/https://' '\"$current$host$custom_PATH/https://';
            sub_filter '\"https://github.goblog.top/host/https://' '\"$current$host$custom_PATH/https://';
            sub_filter "src=\"https://github.goblog.top/host/https://" 'src="$current$host$custom_PATH/https://';
            sub_filter 'src="https://github.goblog.top/host/https://raw.githubusercontent.com/' 'src="$current$host$custom_PATH/$custom_host/';
            sub_filter "src='https://github.goblog.top/host/https://" "src='$current$host$custom_PATH/https://";
            sub_filter "src='https://github.goblog.top/host/https://raw.githubusercontent.com/" "src='$current$host$custom_PATH/$custom_host/";
            sub_filter "href=\"https://github.goblog.top/host/https://" 'href="$current$host$custom_PATH/https://';
            sub_filter 'href="https://github.goblog.top/host/https://raw.githubusercontent.com/' 'href="$current$host$custom_PATH/$custom_host/';
            sub_filter "href='https://github.goblog.top/host/https://" "href='$current$host$custom_PATH/https://";
            sub_filter 'action="https://github.goblog.top/host/https://raw.githubusercontent.com/' 'action="$current$host$custom_PATH/$custom_host/';
            sub_filter "href='https://github.goblog.top/host/https://raw.githubusercontent.com/" "href='$current$host$custom_PATH/$custom_host/";
            sub_filter "\"https://github.goblog.top/host/https://" "\"$current$host$custom_PATH/https://";
            sub_filter "\'https://github.goblog.top/host/https://" "\'$current$host$custom_PATH/https://";

            sub_filter '"search' '"search';
            sub_filter 'youtubei/v1/' 'youtubei/v1/';
            sub_filter ':\"/' ':\"$current$host$custom_PATH/$custom_host/';
            sub_filter "https:\\/\\/accounts.google.com" "$current$host$custom_PATH/https:\\/\\/accounts.google.com";


            sub_filter '"images' '"images';
            sub_filter ', images' ', images';
            sub_filter ', kkkk' ', kkkk';

            sub_filter 'https://github.goblog.top/host/https://raw.githubusercontent.com/../' '$current$host$custom_PATH/$custom_host/https://github.goblog.top/host/https://raw.githubusercontent.com/../';
            sub_filter "'https://github.goblog.top/host/https://$custom_host2" "'$current$host$custom_PATH/$custom_host";
            sub_filter "'https://github.goblog.top/host/https://$custom_host2" "'$current$host$custom_PATH/$custom_host";
            sub_filter "\"https://github.goblog.top/host/https://$custom_host2" "\"$current$host$custom_PATH/$custom_host";
            sub_filter "\"https://github.goblog.top/host/https://$custom_host2" "\"$current$host$custom_PATH/$custom_host";
            set $myurl1 "";
            set $myurl2 "";
            # add_header Proxy-Cache2 "1";


            if ($request_uri ~* ^\/(.+)\/((http|https)://(www.)?([\w-]+(\.)?)+)(.*?)$) {
                set $myurl2 "${current}127.0.0.1${custom_PATH}/${custom_PATH}/${custom_host}";
            }
            if ($unopengzip = 0) {
                set  $myurl1 $custom_host;
            }

            if ($unopengzip = 1) {
                set  $myurl1 $myurl2;
            }
            if ($request_uri ~* ^\/(.+)\/((http|https)://(www.)?([\w-]+(\.)?)+)(.*?)$) {
                proxy_pass $myurl1$7;
            }


        }
	location / {
		#if ( $uri != /search ) {
		#	return 404;
		#}
		rewrite ^(.*)$ https://example.com/host/https://github.com$1 permanent;	#这个地方的example.com 改成和上面一样的
	}
        #location =/generate_204 {
        #    return 204;
        #}
        #location / {
		#return 404;
        #}
    }
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇