From 31fb36cc53f6b384a580c8135c2e67a3b3f42071 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Fri, 10 May 2019 11:11:53 +0800 Subject: [PATCH 01/19] =?UTF-8?q?openresty=20=E5=8D=87=E7=BA=A7=E5=88=B0?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=89=88=EF=BC=9Bpcre-jit=20=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E9=87=8D=E6=96=B0=E5=8A=A0=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup-nginx.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup-nginx.sh b/setup-nginx.sh index f43c52c..e2e23dc 100755 --- a/setup-nginx.sh +++ b/setup-nginx.sh @@ -1,5 +1,5 @@ # 无需 root 运行 -curl -O https://openresty.org/download/openresty-1.15.8.1rc1.tar.gz +curl -O https://openresty.org/download/openresty-1.15.8.1rc2.tar.gz tar zxvf openresty-* cd openresty-* @@ -8,6 +8,7 @@ export PATH=$PATH:/sbin ./configure \ --with-http_v2_module \ --with-http_ssl_module \ + --with-pcre-jit \ --prefix=/home/jsproxy/openresty make From d8abb31254f9f77cd5f455c30773fc442427a891 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Fri, 10 May 2019 11:12:31 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.conf | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api.conf b/api.conf index 7f6e673..49206c2 100644 --- a/api.conf +++ b/api.conf @@ -7,6 +7,8 @@ if ($http_x_jsproxy) { proxy_set_header x-jsproxy 1; proxy_set_header Connection $http_connection; +set $_level ''; +set $_switched ''; set $_url ''; set $_ver ''; set $_ref ''; @@ -19,7 +21,7 @@ location = /preflight { more_set_headers 'access-control-allow-origin: *' 'access-control-allow-methods: GET,POST,PUT,PATCH,TRACE,DELETE,HEAD,OPTIONS' - 'access-control-allow-headers: --url,--referer,--cookie,--origin,--ext,--aceh,--ver,--type,--mode,accept,accept-charset,accept-encoding,accept-language,accept-datetime,authorization,cache-control,content-length,content-type,date,if-match,if-modified-since,if-none-match,if-range,if-unmodified-since,max-forwards,pragma,range,te,upgrade,upgrade-insecure-requests,x-requested-with,chrome-proxy' + 'access-control-allow-headers: --raw-info,--level,--url,--referer,--cookie,--origin,--ext,--aceh,--ver,--type,--mode,accept,accept-charset,accept-encoding,accept-language,accept-datetime,authorization,cache-control,content-length,content-type,date,if-match,if-modified-since,if-none-match,if-range,if-unmodified-since,max-forwards,pragma,range,te,upgrade,upgrade-insecure-requests,x-requested-with,chrome-proxy' 'access-control-max-age: 1728000' ; return 204; @@ -43,7 +45,8 @@ location = /http { 'content-security-policy-report-only' 'x-frame-options' ; - header_filter_by_lua_file ../lua/http-enc-res-hdr.lua; + header_filter_by_lua_file ../lua/http-enc-res-hdr.lua; + body_filter_by_lua_file ../lua/http-body-hash.lua; } From 4bc6a9476a22351818638e0ed070bc68b14b4f36 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Fri, 10 May 2019 11:12:59 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=88=87=E6=8D=A2=E7=9A=84=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E7=BC=93=E5=AD=98=E6=B2=A1=E6=9C=89=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E5=A4=AA=E5=A4=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx.conf | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/nginx.conf b/nginx.conf index d4055eb..1dd3186 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,10 +1,9 @@ http { server { - # server_name example.com; - # ssl_certificate cert/example.com/ecc.cer; - # ssl_certificate_key cert/example.com/ecc.key; - # listen 8443 ssl http2; - listen 8080; + server_name *.etherdream.com; + ssl_certificate cert/etherdream.com/ecc.cer; + ssl_certificate_key cert/etherdream.com/ecc.key; + listen 8443 ssl http2; include api.conf; } @@ -32,8 +31,9 @@ http { # https://nginx.org/en/docs/http/ngx_http_log_module.html # separated by tab (\t) log_format log_proxy escape=none + '01 ' '$time_iso8601 $_origin_id $_ver $remote_addr ' - '$upstream_cache_status $request_time ' + '$_level $_switched $upstream_cache_status $request_time ' '$request_length $bytes_sent ' '$request_method $_url $status $upstream_http_access_control_allow_origin ' '$http_user_agent $_ref $_mode $_type' @@ -44,8 +44,8 @@ http { # 1MB = 8000key proxy_cache_path cache levels=1:2 - keys_zone=my_cache:32m - max_size=20g + keys_zone=my_cache:16m + max_size=2g inactive=6h use_temp_path=off ; From e4d08920e37a4744f6d2aaf02b903c4d6497c042 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Fri, 10 May 2019 11:13:58 +0800 Subject: [PATCH 04/19] =?UTF-8?q?cloudflare=20worker=20=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cf-worker/README.md | 1 + cf-worker/index.js | 78 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 16 deletions(-) diff --git a/cf-worker/README.md b/cf-worker/README.md index e69de29..ff68cc1 100644 --- a/cf-worker/README.md +++ b/cf-worker/README.md @@ -0,0 +1 @@ +https://cloudflareworkers.com/ \ No newline at end of file diff --git a/cf-worker/index.js b/cf-worker/index.js index c63b9f3..96d3d96 100644 --- a/cf-worker/index.js +++ b/cf-worker/index.js @@ -1,12 +1,25 @@ /** * jsproxy cfworker api * - * @update: 2019-05-03 + * @update: 2019-05-07 * @author: EtherDream * @see: https://github.com/EtherDream/jsproxy/ */ +'use strict' + +const PREFLIGHT_INIT = { + status: 204, + headers: new Headers({ + 'access-control-allow-origin': '*', + 'access-control-allow-methods': 'GET,POST,PUT,PATCH,TRACE,DELETE,HEAD,OPTIONS', + 'access-control-allow-headers': '--raw-info,--level,--url,--referer,--cookie,--origin,--ext,--aceh,--ver,--type,--mode,accept,accept-charset,accept-encoding,accept-language,accept-datetime,authorization,cache-control,content-length,content-type,date,if-match,if-modified-since,if-none-match,if-range,if-unmodified-since,max-forwards,pragma,range,te,upgrade,upgrade-insecure-requests,x-requested-with,chrome-proxy', + 'access-control-max-age': '1728000', + }), +} + const pairs = Object.entries + addEventListener('fetch', e => { const ret = handler(e.request) .catch(err => new Response(err)) @@ -15,37 +28,38 @@ addEventListener('fetch', e => { }) -const PREFLIGHT_INIT = { - status: 204, - headers: new Headers({ - 'access-control-allow-origin': '*', - 'access-control-allow-methods': 'GET,POST,PUT,PATCH,TRACE,DELETE,HEAD,OPTIONS', - 'access-control-allow-headers': '--url,--referer,--cookie,--origin,--ext,--aceh,--ver,--type,--mode,accept,accept-charset,accept-encoding,accept-language,accept-datetime,authorization,cache-control,content-length,content-type,date,if-match,if-modified-since,if-none-match,if-range,if-unmodified-since,max-forwards,pragma,range,te,upgrade,upgrade-insecure-requests,x-requested-with,chrome-proxy', - 'access-control-max-age': '1728000', - }), -} - /** * @param {Request} req */ async function handler(req) { const reqHdrRaw = req.headers + if (reqHdrRaw.has('x-jsproxy')) { + return Response.error() + } // preflight - if (reqHdrRaw.has('access-control-request-headers')) { + if (req.method === 'OPTIONS' && + reqHdrRaw.has('access-control-request-headers') + ) { return new Response(null, PREFLIGHT_INIT) } let url = '' let extHdrs = null let acehOld = false + let rawSvr = '' + let rawLen = '' + let rawEtag = '' const reqHdrNew = new Headers(reqHdrRaw) + reqHdrNew.set('x-jsproxy', '1') for (const [k, v] of reqHdrRaw.entries()) { if (!k.startsWith('--')) { continue } + reqHdrNew.delete(k) + const k2 = k.substr(2) switch (k2) { case 'url': @@ -54,6 +68,11 @@ async function handler(req) { case 'aceh': acehOld = true break + case 'raw-info': + // TODO: ,, + [rawSvr, rawLen, rawEtag] = v.split(/,{1,2}/) + break + case 'level': case 'mode': case 'type': break @@ -61,7 +80,11 @@ async function handler(req) { extHdrs = JSON.parse(v) break default: - reqHdrNew.set(k2, v) + if (v) { + reqHdrNew.set(k2, v) + } else { + reqHdrNew.delete(k2) + } break } } @@ -84,7 +107,7 @@ async function handler(req) { let expose = '*' let vary = '--url' - + for (const [k, v] of resHdrOld.entries()) { if (k === 'access-control-allow-origin' || k === 'access-control-expose-headers' || @@ -123,8 +146,31 @@ async function handler(req) { resHdrNew.set('vary', vary) resHdrNew.set('--s', res.status) - return new Response(res.body, { - status: 200, + // verify + const newLen = resHdrOld.get('content-length') || '' + const newEtag = resHdrOld.get('etag') || '' + + const badLen = (rawLen !== newLen) + const badEtag = (rawEtag && rawEtag !== newEtag) + + // resHdrNew.set('--l', rawLen + ',' + newLen) + // resHdrNew.set('--e', rawEtag + ',' + newEtag) + + let status = 200 + let body = res.body + + if (badLen) { + status = 400 + body = `bad len (old: ${rawLen} new: ${newLen})` + resHdrNew.set('cache-control', 'no-cache') + } + // else if (badEtag) { + // status = 400 + // body = `bad etag (old: ${rawEtag} new: ${newEtag})` + // } + + return new Response(body, { + status, headers: resHdrNew, }) } \ No newline at end of file From 9ea8fd3f6cef2bc3fa3081e5c94f7709e0cb1ca7 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Fri, 10 May 2019 11:14:33 +0800 Subject: [PATCH 05/19] =?UTF-8?q?brotli=20=E5=8E=8B=E7=BC=A9=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log-svc/setup-brotli.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/log-svc/setup-brotli.sh b/log-svc/setup-brotli.sh index cca8aa2..d4466fe 100644 --- a/log-svc/setup-brotli.sh +++ b/log-svc/setup-brotli.sh @@ -1,15 +1,13 @@ #!/usr/bin/env bash # 功能:安装 brotli 压缩工具 -# 依赖:cmake(yum install -y cmake) git clone --depth 1 https://github.com/google/brotli.git cd brotli -./configure-cmake make mkdir -p ~/tools -mv brotli ~/tools +mv bin/brotli ~/tools cd .. rm -rf brotli \ No newline at end of file From 16697c63a4b11d2c597e40e4a87e1fb0dca96f6f Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Fri, 10 May 2019 11:15:35 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=A4=A7=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E4=B8=8D=E8=BF=94=E5=9B=9E=E5=86=85=E5=AE=B9=EF=BC=8C?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E6=B5=8F=E8=A7=88=E5=99=A8=E8=B5=B0=20cfwork?= =?UTF-8?q?er?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/http-body-hash.lua | 5 ++ lua/http-dec-req-hdr.lua | 5 +- lua/http-enc-res-hdr.lua | 170 ++++++++++++++++++++++++++++++--------- 3 files changed, 141 insertions(+), 39 deletions(-) create mode 100644 lua/http-body-hash.lua diff --git a/lua/http-body-hash.lua b/lua/http-body-hash.lua new file mode 100644 index 0000000..6504ac8 --- /dev/null +++ b/lua/http-body-hash.lua @@ -0,0 +1,5 @@ +if ngx.ctx._switched then + local chunk = ngx.arg[1] + ngx.arg[1] = #chunk .. ',' .. ngx.crc32_long(chunk) + ngx.arg[2] = true +end \ No newline at end of file diff --git a/lua/http-dec-req-hdr.lua b/lua/http-dec-req-hdr.lua index f7a6c39..46c1f4e 100644 --- a/lua/http-dec-req-hdr.lua +++ b/lua/http-dec-req-hdr.lua @@ -22,13 +22,14 @@ for k, v in pairs(hdrs) do ngx.var._mode = v elseif k == 'aceh' then ngx.ctx._acehOld = true + elseif k == 'level' then + ngx.var._level = v + ngx.ctx._level = tonumber(v) elseif k == 'ext' then extHdrs = require('cjson').decode(v) else if k == 'referer' then ngx.var._ref = v - else if k == 'cookie' then - ngx.ctx._hasCookie = true end ngx.req.set_header(k, v) end diff --git a/lua/http-enc-res-hdr.lua b/lua/http-enc-res-hdr.lua index a1a21cd..7322b39 100644 --- a/lua/http-enc-res-hdr.lua +++ b/lua/http-enc-res-hdr.lua @@ -3,16 +3,6 @@ -- 备注: -- aceh = HTTP 返回头的 access-control-expose-headers 字段 - --- -if - ngx.req.get_method() == 'GET' and - not ngx.ctx._hasCookie -then - -end - - -- 无论浏览器是否支持,aceh 始终包含 * local expose = '*' @@ -22,6 +12,133 @@ local detail = ngx.ctx._acehOld -- 由于接口路径固定,为避免被缓存,以请求头的 --url 值区分缓存 local vary = '--url' + +local function addHdr(k, v) + ngx.header[k] = v + if detail then + expose = expose .. ',' .. k + end +end + + +local function flushHdr() + if detail then + expose = expose .. ',--s' + -- 该字段不在 aceh 中,如果浏览器能读取到,说明支持 * 通配 + ngx.header['--t'] = '1' + end + + ngx.header['access-control-expose-headers'] = expose + ngx.header['access-control-allow-origin'] = '*' + ngx.header['vary'] = vary + + local status = ngx.status + if + status == 301 or + status == 302 or + status == 303 or + status == 307 or + status == 308 + then + ngx.status = status + 10 + end + ngx.header['--s'] = status +end + + +local function addVary(v) + if type(v) == 'table' then + vary = vary .. ',' .. table.concat(v, ',') + else + vary = vary .. ',' .. v + end +end + + +local function nodeSwitched() + local status = ngx.status + if status ~= 200 and status ~= 206 then + return false + end + + local level = ngx.ctx._level + if level == nil or level == 0 then + return false + end + + if ngx.req.get_method() ~= 'GET' then + return false + end + + if ngx.header['set-cookie'] ~= nil then + return false + end + + local resLenStr = ngx.header['content-length'] + if resLenStr == nil then + return false + end + + -- 小于 400KB 的资源不走加速 + local resLenNum = tonumber(resLenStr) + if resLenNum == nil or resLenNum < 1000 * 400 then + return false + end + + -- -- cache time + -- local ccStr = ngx.header['cache-control'] + -- if ccStr == nil then + -- return false + -- end + -- if type(ccStr) == 'table' then + -- ccStr = table.concat(ccStr, ',') + -- end + + -- -- `cache-control: xxxxx, max-age=31536000, xxxxx` + -- local regex = [[(?:^|;\s*)max-age=(\d+)]] + -- local m = ngx.re.match(ccStr, regex, 'oi') + -- if m == nil then + -- return false + -- end + + -- local seconds = tonumber(m[1]) + -- if seconds == nil then + -- return false + -- end + + -- if seconds < 3600 * 24 then + -- return false + -- end + + local addr = ngx.var.upstream_addr or '' + local etag = ngx.header['etag'] or '' + local last = ngx.header['last-modified'] or '' + -- TODO: , -> ,, + local info = addr .. ',' .. resLenStr .. ',' .. etag .. ',' .. last + + -- clear all res headers + local h, err = ngx.resp.get_headers() + for k, v in pairs(h) do + ngx.header[k] = nil + end + + addHdr('--raw-info', info) + addHdr('--switched', '1') + + ngx.header['cache-control'] = 'no-cache' + ngx.var._switched = resLenStr + ngx.ctx._switched = true + + flushHdr() + return true +end + + +if nodeSwitched() then + return +end + + local h, err = ngx.resp.get_headers() for k, v in pairs(h) do if @@ -32,30 +149,18 @@ for k, v in pairs(h) do k == 'set-cookie' then if type(v) == 'table' then + -- 重复的字段,例如 Set-Cookie + -- 转换成 1-Set-Cookie, 2-Set-Cookie, ... for i = 1, #v do - local x = i .. '-' .. k - ngx.header[x] = v[i] - - if detail then - expose = expose .. ',' .. x - end + addHdr(i .. '-' .. k, v[i]) end else - local x = '--' .. k - ngx.header[x] = v - - if detail then - expose = expose .. ',' .. x - end + addHdr('--' .. k, v) end ngx.header[k] = nil elseif k == 'vary' then - if type(v) == 'table' then - vary = vary .. ',' .. table.concat(v, ',') - else - vary = vary .. ',' .. v - end + addVary(v) elseif detail and -- 非简单头无法被 fetch 读取,需添加到 aceh 列表 -- @@ -71,13 +176,4 @@ for k, v in pairs(h) do end end -if detail then - expose = expose .. ',--s' - ngx.header['--t'] = '1' -end - -ngx.header['access-control-expose-headers'] = expose -ngx.header['access-control-allow-origin'] = '*' -ngx.header['vary'] = vary -ngx.header['--s'] = ngx.status -ngx.status = 200 \ No newline at end of file +flushHdr() \ No newline at end of file From d9c828e7eba0e38196901e05d05605e5b2c4ee4d Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Fri, 10 May 2019 11:16:17 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20nginx=20=E6=AD=A3?= =?UTF-8?q?=E5=88=99=E4=BB=A3=E6=9B=BF=20lua=20=E6=AD=A3=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/worker.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lua/worker.lua b/lua/worker.lua index 7e9a1b2..557781f 100644 --- a/lua/worker.lua +++ b/lua/worker.lua @@ -6,19 +6,18 @@ if ngx.worker.id() ~= 0 then end local function buildDevTrafficFn(dev) - -- 0 1 2 3 4 5 6 7 - -- eth0: bytes packets errs drop fifo frame compressed multicast - -- bytes packets errs drop fifo colls carrier compressed - local regex = dev .. ':%s+(%d+)%s+' .. ('%d+%s+'):rep(7) .. '(%d+)' + local regex = dev .. + [[:\s+(\d+)\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+\d+\s+(\d+)]] + -- 0 1 2 3 4 5 6 7 | 8 + -- eth0: bytes packets errs drop fifo frame compress multi| bytes local lastRxBytes = 0 local lastTxBytes = 0 return function(str) - local - sRxBytes, - sTxBytes - = str:match(regex) + local m = ngx.re.match(str, regex, 'oi') + local sRxBytes = m[1] + local sTxBytes = m[2] if sTxBytes == nil then return '0,0' From 43a1d96e94f588075fc8f5a6f071b26155132801 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Fri, 10 May 2019 11:46:29 +0800 Subject: [PATCH 08/19] test --- upload.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/upload.sh b/upload.sh index 73a40fb..827467e 100755 --- a/upload.sh +++ b/upload.sh @@ -6,6 +6,8 @@ NODE=( node-aliyun-hk node-aliyun-sg node-bwh-los + node-justhost-moscow + node-bungee ) for v in ${NODE[@]}; do echo "$v upload ..." From bfea3e976634bcb6dd6530995b4ac60f02c1a010 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Sat, 11 May 2019 09:11:33 +0800 Subject: [PATCH 09/19] update --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f502d3f..c9c9e12 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ https://zjcqoo.github.io/-----https://www.google.com (目前仍在更新中,最好使用隐身模式访问,避免缓存导致的问题) -[之前版本](https://github.com/EtherDream/jsproxy/tree/first-ver)已不再更新,但[演示服务](https://jsproxy.tk/)仍保留一段时间。 +[之前版本](https://github.com/EtherDream/jsproxy/tree/first-ver)已不再更新。 # 安装 -新建一个名为 `jsproxy:nobody` 用户,在其主目录安装 nginx: +新建一个 `jsproxy:nobody` 用户,在其主目录安装 nginx: ```bash groupadd nobody @@ -164,6 +164,54 @@ https://zjcqoo.github.io/-----https://www.google.com 虽然依旧简陋,但比之前好。提供了线路切换、预加载的功能。 + +# 当前开发中的功能... + +## 增加节点切换 + +目前尝试将服务器分为两种:高级(延时低、带宽小、费用高),低级(延时高、带宽大、费用低)。 + +浏览器首先访问高级服务器,如果返回的是静态资源且体积较大,服务器只返回资源属性(大小、修改时间、首块哈希等),浏览器随后通过低级服务器获取完整资源;如果获取到的属性和之前不一致(例如 IP 变化导致),再从高级服务器获取完整内容。 + +这样设计,是为了降低高级服务器的带宽和流量成本,同时充分利用廉价服务器的资源。 + +目前演示中的低级服务使用的是 ClodeFlare Worker,其费用为 100 万次请求 / $0.5,没有带宽和流量限制,但延时较大,适合于体积较大的资源代理;高级服务为阿里轻量云,延时相对较小,上行带宽和流量有限,但下行流量免费且带宽较大,因此合适较小资源的代理,及其较大资源的属性获取。 + +使用这种方案,理想情况下可以支撑上百人同时观看高清视频。(当然现实中不少视频网站会关联用户 IP,导致节点切换失败,最终仍走高级服务器,难以达到这个数值) + +未来会尝试进一步细分请求的优先级。例如同样是获取视频的请求,不同的片段范围,其优先级是不同的。当首次打开或者拖动进度时,用户希望能尽快看到内容,这就需要更高的优先级;当视频缓冲足够时,这时延时和稳定性已不再重要,因此可以走更廉价的节点。 + +当然具体的实现细节目前仍在探索和优化中,本质意义自然是物尽其用。这是一个很有意思的话题,有兴趣的可以交流讨论。 + + +# 类似项目 + +目前找到的都是传统后端替换 URL 的方案。当然后端替换也有不少优点,例如浏览器兼容性高,甚至低版本的 IE 都可以使用。 + +## zmirror + +GitHub: https://github.com/aploium/zmirror + +## php-proxy + +GitHub: https://github.com/jenssegers/php-proxy + + +# 项目意义 + +本项目主要用于以下技术的研究: + +* 网站镜像 / 沙盒化 + +* 钓鱼网站检测技术 + +* 前端资源访问加速 + +当然请勿将本项目用于非法用途,否则后果自负。 + +Demo 页面文明使用,不要进行登陆等涉及隐私的操作。 + + # License MIT \ No newline at end of file From 1cd9b4692c8f2a268f67127366e8299d8b35bccd Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Sun, 12 May 2019 10:40:32 +0800 Subject: [PATCH 10/19] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20nginx=20lua=5Fload?= =?UTF-8?q?=5Fresty=5Fcore=20failed=20=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/nginx.conf b/nginx.conf index 1dd3186..da0b200 100644 --- a/nginx.conf +++ b/nginx.conf @@ -62,6 +62,7 @@ http { # traffic statistics lua_shared_dict traff 16k; + lua_load_resty_core off; lua_package_path ./lua/?.lua; init_by_lua_file ../lua/init.lua; init_worker_by_lua_file ../lua/worker.lua; From 15c8fc52bcb8cd9937ac9f090be33ef989489c04 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Sun, 12 May 2019 10:40:49 +0800 Subject: [PATCH 11/19] update --- lua/worker.lua | 3 +++ upload.sh | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lua/worker.lua b/lua/worker.lua index 557781f..70b2866 100644 --- a/lua/worker.lua +++ b/lua/worker.lua @@ -16,6 +16,9 @@ local function buildDevTrafficFn(dev) return function(str) local m = ngx.re.match(str, regex, 'oi') + if m == nil then + return '0,0' + end local sRxBytes = m[1] local sTxBytes = m[2] diff --git a/upload.sh b/upload.sh index 827467e..7550515 100755 --- a/upload.sh +++ b/upload.sh @@ -3,11 +3,12 @@ HOST=etherdream.com NODE=( - node-aliyun-hk - node-aliyun-sg - node-bwh-los - node-justhost-moscow - node-bungee + # node-aliyun-hk + # node-aliyun-sg + # node-bwh-los + # node-justhost-moscow + # node-bungee + node-justhost-novosibirsk ) for v in ${NODE[@]}; do echo "$v upload ..." From c236b28254259d2248fa51403daac43bc1d3e715 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Mon, 13 May 2019 17:46:06 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E4=BF=9D=E7=95=99=20HTTP=20=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=A4=B4=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/http-enc-res-hdr.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lua/http-enc-res-hdr.lua b/lua/http-enc-res-hdr.lua index 7322b39..4d75d48 100644 --- a/lua/http-enc-res-hdr.lua +++ b/lua/http-enc-res-hdr.lua @@ -28,11 +28,12 @@ local function flushHdr() ngx.header['--t'] = '1' end + local status = ngx.status + ngx.header['access-control-expose-headers'] = expose ngx.header['access-control-allow-origin'] = '*' ngx.header['vary'] = vary - - local status = ngx.status + ngx.header['--s'] = status if status == 301 or status == 302 or @@ -40,9 +41,9 @@ local function flushHdr() status == 307 or status == 308 then - ngx.status = status + 10 + status = status + 10 end - ngx.header['--s'] = status + ngx.status = status end From c07311d30158a429ffd96a1a2ac27f6591f45695 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Mon, 13 May 2019 17:48:25 +0800 Subject: [PATCH 13/19] =?UTF-8?q?=E4=BF=9D=E7=95=99=20http=208080?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nginx.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/nginx.conf b/nginx.conf index da0b200..0ab2c52 100644 --- a/nginx.conf +++ b/nginx.conf @@ -4,6 +4,7 @@ http { ssl_certificate cert/etherdream.com/ecc.cer; ssl_certificate_key cert/etherdream.com/ecc.key; listen 8443 ssl http2; + listen 8080; include api.conf; } From 984a81d22edb201a5ab87090120c6c4f22c1f3a7 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Mon, 13 May 2019 17:48:41 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- upload.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/upload.sh b/upload.sh index 7550515..72bf80b 100755 --- a/upload.sh +++ b/upload.sh @@ -3,12 +3,12 @@ HOST=etherdream.com NODE=( - # node-aliyun-hk - # node-aliyun-sg - # node-bwh-los - # node-justhost-moscow - # node-bungee + node-aliyun-hk + node-aliyun-sg + node-bwh-los + node-justhost-moscow node-justhost-novosibirsk + node-bungee ) for v in ${NODE[@]}; do echo "$v upload ..." From 57e1e22061b1819466ad631d72a0574af7309c4f Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Mon, 13 May 2019 17:48:57 +0800 Subject: [PATCH 15/19] =?UTF-8?q?README=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c9c9e12..54eddd1 100644 --- a/README.md +++ b/README.md @@ -44,10 +44,15 @@ yum install -y \ ~/server/run.sh ``` -访问:https://etherdream.github.io/jsproxy-localtest/-----https://github.com/ +访问:https://zjcqoo.github.io/#local (localhost 测试节点) ![](https://raw.githubusercontent.com/EtherDream/jsproxy-localtest/temp/preview.png) +![](https://raw.githubusercontent.com/EtherDream/jsproxy-localtest/temp/preview2.png) + + +> 如果一直显示加载中,可尝试修改 `nginx.conf` 中 DNS 配置。(默认为 `1.1.1.1`,有些地区很慢) + 注意,**当前项目只提供接口服务**,浏览器端脚本和页面不在本项目。这样做是为了让接口和界面分离,意义参见后续。 From ef93a94ee7dec0b6cc0e732f1ded327d2dda162e Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Tue, 14 May 2019 10:25:20 +0800 Subject: [PATCH 16/19] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=AE=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/run.sh b/run.sh index d795821..54f00d5 100755 --- a/run.sh +++ b/run.sh @@ -1,10 +1,4 @@ -NGX_BIN=/home/jsproxy/openresty/nginx/sbin/nginx - -# local test -if [ ! -f $NGX_BIN ]; then - NGX_BIN=/usr/local/openresty/nginx/sbin/nginx -fi - +NGX_BIN=$HOME/openresty/nginx/sbin/nginx CUR_DIR=$(cd `dirname $0` && pwd) if [ $1 ]; then From 5aa22a40a515fb9203025e725aeda03b02298bcf Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Tue, 14 May 2019 17:08:37 +0800 Subject: [PATCH 17/19] bin install test --- i.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 i.sh diff --git a/i.sh b/i.sh new file mode 100644 index 0000000..c1a3284 --- /dev/null +++ b/i.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +CDN=https://cdn.jsdelivr.net/gh/etherdream/jsproxy-bin@master/dist/ +DST=/home/jsproxy/setup.sh + + +groupadd nobody +useradd jsproxy -g nobody --create-home + +curl -s "$CDN/setup.sh" -o $DST +chmod +x $DST + +su - jsproxy -c $DST \ No newline at end of file From fbb537d5ead2e7ae5fbcae8c3664889b863396e8 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Tue, 14 May 2019 17:14:34 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E4=B8=80=E9=94=AE=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- i.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/i.sh b/i.sh index c1a3284..b34efea 100644 --- a/i.sh +++ b/i.sh @@ -1,13 +1,12 @@ #!/usr/bin/env sh -CDN=https://cdn.jsdelivr.net/gh/etherdream/jsproxy-bin@master/dist/ DST=/home/jsproxy/setup.sh - groupadd nobody useradd jsproxy -g nobody --create-home -curl -s "$CDN/setup.sh" -o $DST +echo "download main script ..." +curl -s "https://raw.githubusercontent.com/EtherDream/jsproxy-bin/master/setup.sh" -o $DST chmod +x $DST su - jsproxy -c $DST \ No newline at end of file From 1039991fb22e497ec6aaa86cf5601a26bd2cd162 Mon Sep 17 00:00:00 2001 From: zjcqoo Date: Tue, 14 May 2019 17:35:17 +0800 Subject: [PATCH 19/19] =?UTF-8?q?=E4=B8=80=E9=94=AE=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 +++++++++++--- i.sh | 5 +++-- log-svc/svc.sh | 3 ++- release.sh | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100755 release.sh diff --git a/README.md b/README.md index 54eddd1..97f6c79 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,24 @@ https://zjcqoo.github.io/-----https://www.google.com [之前版本](https://github.com/EtherDream/jsproxy/tree/first-ver)已不再更新。 -# 安装 +# 一键安装 + +```sh +curl https://raw.githubusercontent.com/EtherDream/jsproxy/master/i.sh | sh +``` + +(暂时只支持 Linux x64 版本。如果安装失败,尝试手动安装) + + +# 手动安装 新建一个 `jsproxy:nobody` 用户,在其主目录安装 nginx: ```bash groupadd nobody useradd jsproxy -g nobody --create-home -su jsproxy +su - jsproxy -cd ~ git clone --depth=1 https://github.com/EtherDream/jsproxy.git server cd server diff --git a/i.sh b/i.sh index b34efea..0f5fe55 100644 --- a/i.sh +++ b/i.sh @@ -1,12 +1,13 @@ #!/usr/bin/env sh +SRC=https://raw.githubusercontent.com/EtherDream/jsproxy-bin/master/setup.sh DST=/home/jsproxy/setup.sh groupadd nobody useradd jsproxy -g nobody --create-home echo "download main script ..." -curl -s "https://raw.githubusercontent.com/EtherDream/jsproxy-bin/master/setup.sh" -o $DST -chmod +x $DST +curl -s $SRC -o $DST +chmod +x $DST su - jsproxy -c $DST \ No newline at end of file diff --git a/log-svc/svc.sh b/log-svc/svc.sh index eecd5ee..fd8fd29 100755 --- a/log-svc/svc.sh +++ b/log-svc/svc.sh @@ -2,10 +2,11 @@ # 功能:定时调用 backup.sh echo "log svc running" +CUR_DIR=$(cd `dirname $0` && pwd) # 也可用 crontab while true do - ./backup.sh + $CUR_DIR/backup.sh sleep 60 done \ No newline at end of file diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..ee2a603 --- /dev/null +++ b/release.sh @@ -0,0 +1 @@ +git archive --format=tar --prefix=server/ master > ../bin/src/server.tar