关于nginx:通过nginx自建github加速debianubuntucentos镜像源

3次阅读

共计 3219 个字符,预计需要花费 9 分钟才能阅读完成。

转载留作备份:
转载起源:https://run.la/s/169.html

 贴一份本人反向代理减速国外网站,次要代理 github 和一些源。server
{
    listen 443 ssl http2 reuseport;
    #http2 示意启用 http2 协定,http2 个别须要 openssl 1.0.2+ 以上版本反对, 大部分 linux 零碎须要自行编译 nginx 作为反对,ubuntu16.04 能够间接反对。listen 80 reuseport;
    #同时监听 80 端口。#reuseport 进步 nginx 性能,有趣味能够搜索引擎

    location ~* .(conf|sql|bak)$ {deny all;}

    ssl_certificate ssl/p.run.la.pem;
    ssl_certificate_key ssl/p.run.la.key;

    ssl_certificate ssl/p.run.la.ecdsa.pem;
    ssl_certificate_key ssl/p.run.la.ecdsa.key;
    #配置双证书,一个是 rsa 算法的证书,一个是 ecc,ecc 算法效率更高,然而并不反对某些老的零碎。ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    #配置加密协议,如果要反对 ie6 还须要加上 SSLv3,然而安全性会升高

    ssl_session_timeout      1d;
    #缓存工夫

    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AES128:EECDH+aRSA+AES128:RSA+AES128:EECDH+ECDSA+AES256:EECDH+aRSA+AES256:RSA+AES256:EECDH+ECDSA+3DES:EECDH+aRSA+3DES:RSA+3DES:!MD5;
    #配置 https 加密算法,chacha20 对称算法耗费更少,对于挪动端更敌对,然而须要自行编译 nginx,打 Cloudflare 补丁。ssl_prefer_server_ciphers on;


    ssl_session_cache        shared:SSL:50m;

    ssl_session_tickets      on;
    #配置 ssl 缓存

    ssl_stapling             on;
    #开启 OCSP, 因为 Let's Encryptc 证书的起因,我开启 ocsp 无需更多设置。server_name p.run.la; #绑定的域名

    if ($request_method !~ ^(GET|HEAD|POST)$ ) {return    444;}

    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;}
    #屏蔽搜索引擎

    resolver                 8.8.8.8 8.8.4.4  valid=600s;
    #设置域名解析的 dns 服务器
    resolver_timeout         10s;
    #设置 dns 解析超时工夫。location ~ ^/(repo\.mongodb\.com|repo\.mysql\.com|www\.debian\.org|deb\.debian\.org|security\.debian\.org|cdn-fastly\.deb.debian\.org|nginx\.org|github\.com|codeload\.github\.com|yum\.dockerproject\.org)(\/.*)$ {
        #须要代理的域名正则,防止有人用来代理某些被墙的网站,导致反向代理被 gfw 误杀,会的人本人改改就能够反向代理所有网站了,其实在通过 sub_filter 替换链接能够做到拜访大部分网站,然而当初有份写好的,因为某 VPS 商,导致数据丢了,有趣味的能够本人试着填一下。proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        #将用户 ip 放到申请协定头内,个别用来通知后端服务器,是谁拜访的网站。proxy_set_header Accept-Encoding "";
        #通知被代理网站,不要压缩内容,否则 sub_filter 会生效。proxy_set_header Connection "";
        #启用 http1.1 协定
        proxy_http_version 1.1;
        #同上
        proxy_connect_timeout    10s;
        #设置连贯超时
        proxy_read_timeout       10s;
        #设置读取超时
        proxy_set_header Host $1;
        #设置 host,域名
        proxy_redirect ~^(http:\/\/|https:\/\/)?(.*)$ $1$server_name/$2;
        #将原 301 跳转,从新跳转回本域名。sub_filter 'src="/''src="/$1/';
        sub_filter 'src="http://$1''src="http://$server_name/$1';
        sub_filter 'src="https://$1''src="https://$server_name/$1';
        sub_filter 'src="//$1''src="//$server_name/$1';
        #替换网页内链接地址。sub_filter 'href="/''href="/$1/';
        sub_filter 'href="http://$1''href="http://$server_name/$1';
        sub_filter 'href="https://$1''href="https://$server_name/$1';
        sub_filter 'href="//$1''href="//$server_name/$1';
        #同上

        sub_filter 'action="/''action="/$1/';
        sub_filter 'action="http://$1''action="http://$server_name/$1';
        sub_filter 'action="https://$1''action="https://$server_name/$1';
        sub_filter 'action="//$1''action="//$server_name/$1';
        #同上

        sub_filter_once off;
        #替换屡次

        proxy_hide_header Strict-Transport-Security;
        #暗藏被代理网站返回回来的协定头“Strict-Transport-Security”,防止启动 hsts,具体搜索引擎 hsts

        set $query_mark "";
        if ($query_string != "") {set $query_mark "?${query_string}";
        }
        #因为 nginx 并不匹配 url 前面的? 参数,而是应用“$query_string”贮存。proxy_pass $scheme://$1$2${query_mark};
        #$scheme 是以后拜访的协定,http、https
    }

    root  /home/wwwroot/p.run.la;
    #设置目录。}

配置完后就能够应用 https:// 域名 /github.com/,拜访 github 了,比方 https://p.run.la/github.com/
正文完
 0