转载留作备份:
转载起源: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/