فهرست منبع

更新安装脚本和备注

zjcqoo 6 سال پیش
والد
کامیت
8d2238de3e
8فایلهای تغییر یافته به همراه207 افزوده شده و 59 حذف شده
  1. 14 54
      README.md
  2. 0 0
      acme/.well-known/acme-challenge/.gitignore
  3. 11 3
      allowed-sites.conf
  4. 60 0
      docs/cert-auto.md
  5. 69 0
      docs/cert-manual.md
  6. 24 0
      docs/deploy.md
  7. 29 1
      docs/setup.md
  8. 0 1
      nginx.conf

+ 14 - 54
README.md

@@ -7,11 +7,7 @@ https://zjcqoo.github.io/-----https://www.google.com
 
 
 # 最近更新
 # 最近更新
 
 
-* 2019-05-23 前端配置文件动态加载,无需打包脚本。目前可在 github 上直接修改配置在线部署
-
-* 2019-05-21 首页静态资源从 CDN 加载
-
-* 2019-05-20 安装脚本更新
+* 2019-05-26 安装时自动申请证书(使用 xip.io 域名),安装后即可预览
 
 
 [查看更多](changelogs)
 [查看更多](changelogs)
 
 
@@ -19,29 +15,21 @@ https://zjcqoo.github.io/-----https://www.google.com
 # 安装
 # 安装
 
 
 ```bash
 ```bash
-curl -O https://raw.githubusercontent.com/EtherDream/jsproxy/master/i.sh && bash i.sh
+curl -O https://raw.githubusercontent.com/EtherDream/jsproxy/dev/i.sh && bash i.sh
 ```
 ```
 
 
-如果安装失败,尝试[手动安装](docs/compile.md)。
-
+* 自动安装目前只支持 Linux x64,并且需要 root 权限
 
 
-# 测试
+* 安装过程中 80 端口能被外网访问(申请 HTTPS 证书)
 
 
-可通过如下命令,验证代理是否生效:
+无法满足上述条件,或想了解安装细节,可尝试[手动安装](docs/setup.md)。
 
 
-```bash
-curl http://服务器IP:8080/http \
-  -H '--url: https://raw.githubusercontent.com/EtherDream/jsproxy/master/test/works.txt' \
-  -H 'Origin: http://localhost'
-```
 
 
-正常情况下,显示 `ok`。如果无法连接,检查 8080/8443 端口是否添加到防火墙。
+# 预览
 
 
-其他错误,可尝试查看错误日志:
+访问 `https://zjcqoo.github.io#test=服务器IP.xip.io:8443` 
 
 
-```bash
-cat /home/jsproxy/server/nginx/logs/error.log
-```
+使用自己的 github.io 或其他站点,可参考[站点部署](docs/deploy.md)。
 
 
 
 
 # 维护
 # 维护
@@ -66,52 +54,24 @@ tail server/nginx/logs/proxy.log
 目前暂未实现开机自启动。
 目前暂未实现开机自启动。
 
 
 
 
-# 快捷部署
-
-假如你的 github 用户名为 `mygithub`,域名为 `example.com`。
-
-## 服务端
-
-1.解析域名到自己服务器。申请证书,保存到 `cert/example.com/` 目录下
-
-2.修改 `nginx.conf` 中域名和证书的配置(默认被注释)
-
-3.在 `allowed-sites.conf` 中添加 Web 空间的地址:
-
-```
-https://mygithub.github.io     'my';
-```
-
-4.执行 `./run.sh reload` 重启服务
-
-
-## 客户端
-
-1.进入 https://github.com/zjcqoo/zjcqoo.github.io 点击 fork。
-
-2.进入 Settings 页面,仓库重命名成 `mygithub.github.io`
-
-3.进入 `conf.js` 文件,在线编译
-
-4.访问 `https://mygithub.github.io` 预览
-
-> 本项目支持子路径。仓库可重命名成任何名字(例如 x),然后创建 `gh-pages` 分支,通过 `https://用户名.github.io/x` 也能访问。
+# 禁止外链
 
 
+默认情况下,代理接口允许所有 `github.io` 子站点调用,这可能导致不必要的流量消耗。
 
 
-浏览器端源码可查看:https://github.com/EtherDream/jsproxy-browser
+如果希望只给自己网站使用,可编辑 `allowed-sites.conf`。(重启服务生效)
 
 
 
 
 # 安全策略
 # 安全策略
 
 
-如果不希望代理访问内网,可执行 `setup-ipset.sh` 避免 SSRF 风险
+如果不希望代理访问内网(避免 SSRF 风险),可执行 `setup-ipset.sh`:
 
 
 ```bash
 ```bash
-/home/jsproxy/setup-ipset.sh
+/home/jsproxy/server/setup-ipset.sh
 ```
 ```
 
 
 > 需要 root 权限,依赖 `ipset` 命令
 > 需要 root 权限,依赖 `ipset` 命令
 
 
-该脚本可禁止 `jsporxy` 用户访问内网(针对 TCP)。nginx 之外的程序也生效,但不影响其他用户。
+该脚本可禁止 `jsporxy` 用户访问保留 IP 段(针对 TCP)。nginx 之外的程序也生效,但不影响其他用户。
 
 
 
 
 # 项目特点
 # 项目特点

+ 0 - 0
acme/.well-known/acme-challenge/.gitignore


+ 11 - 3
allowed-sites.conf

@@ -1,10 +1,18 @@
 #
 #
-# 授权哪些站点可使用本服务
+# 授权哪些站点可使用本服务,防止外链
 #
 #
 # 本服务会校验 HTTP 请求头 origin 字段,如果不在该列表,则拒绝代理
 # 本服务会校验 HTTP 请求头 origin 字段,如果不在该列表,则拒绝代理
 # 每个 URL 对应一个短别名,用于日志记录
 # 每个 URL 对应一个短别名,用于日志记录
 # 注意 URL 不包含路径部分(结尾没有 /)
 # 注意 URL 不包含路径部分(结尾没有 /)
 #
 #
+http://127.0.0.1                  '127';
 http://localhost                  'lo';
 http://localhost                  'lo';
-https://etherdream.github.io      'gh-eth';
-https://zjcqoo.github.io          'gh-qoo';
+
+# 接口和网站同源,这种情况下 origin 为空
+''                                'mysite';
+
+# ~ 开头为正则匹配,此处允许 github.io 所有子站点
+~^https://([\w-]+).github.io$     'gh-$1';
+
+# 允许任何站点使用
+# ~(.*)                             '$1';

+ 60 - 0
docs/cert-auto.md

@@ -0,0 +1,60 @@
+# 自动申请 HTTPS 证书
+
+1.转发 80 端口到 10080 端口(需要 root 权限)
+
+```bash
+iptables -t nat -I PREROUTING 1 -p tcp --dport 80 -j REDIRECT --to-ports 10080
+```
+
+2.安装 acme.sh(无需 root 权限,在 `jsproxy` 用户下安装)
+
+```bash
+su - jsproxy
+curl https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh | INSTALLONLINE=1  sh
+```
+
+3.申请证书
+
+```bash
+# 服务器公网 IP
+ip=$(curl -s https://api.ipify.org)
+domain="$ip.xip.io"
+
+dist=~/server/cert/$domain
+mkdir -p $dist
+
+~/.acme.sh/acme.sh \
+  --issue \
+  -d $domain \
+  --keylength ec-256 \
+  --webroot ~/server/acme
+
+~/.acme.sh/acme.sh \
+  --install-cert \
+  -d $domain \
+  --ecc \
+  --key-file $dist/ecc.key \
+  --fullchain-file $dist/ecc.cer
+```
+
+4.生成配置文件:
+
+```conf
+echo "
+listen                8443 ssl http2;
+ssl_certificate       cert/$domain/ecc.cer;
+ssl_certificate_key   cert/$domain/ecc.key;
+" > ~/server/cert/cert.conf
+```
+
+重启服务:`~/server/run.sh reload`
+
+5.验证
+
+访问 `https://服务器IP.xip.io:8443/`,没出现证书错误即成功(404 等错误不影响)。
+
+6.关闭 80 端口转发
+
+```bash
+iptables -t nat -D PREROUTING 1
+```

+ 69 - 0
docs/cert-manual.md

@@ -0,0 +1,69 @@
+# 手动申请 HTTPS 证书
+
+在线申请:https://www.sslforfree.com
+
+
+## 方案 1 —- 通过 80 端口验证
+
+前提条件:需要 root 权限
+
+1.输入 `服务器IP.xip.io`
+
+2.Manual Verification -> Manually Verify Domain
+
+3.Download File
+
+4.文件保存到服务器 `~/server/acme/.well-known/acme-challenge/` 目录
+
+5.转发 80 端口到 10080 端口(需要 root 权限)
+
+```bash
+iptables -t nat -I PREROUTING 1 -p tcp --dport 80 -j REDIRECT --to-ports 10080
+```
+
+当然也可以使用其他 Web 服务,只要该文件能被外部访问就可以。
+
+6.测试链接能否访问(Verify successful upload by visiting the following links in your browser)
+
+7.Download SSL Certificate
+
+8.保存证书
+
+`Certificate` 保存到 `~/server/cert/xip.io/cert`
+
+`Private Key` 保存到 `~/server/cert/xip.io/key`
+
+编辑文件 `~/server/cert/cert.conf`
+
+```conf
+listen                8443 ssl http2;
+ssl_certificate       cert/xip.io/cert;
+ssl_certificate_key   cert/xip.io/key;
+```
+
+重启服务:`~/server/run.sh reload`
+
+9.验证
+
+访问 `https://服务器IP.xip.io:8443/`,没出现证书错误即成功(404 等错误不影响)。
+
+10.关闭 80 端口转发
+
+```bash
+iptables -t nat -D PREROUTING 1
+```
+
+
+## 方案 2 —- 通过 DNS 验证
+
+前提条件:拥有域名控制权(`xip.io` 不支持)
+
+1.输入域名
+
+2.Manual Verification (DNS) -> Manually Verify Domain
+
+3.根据提示,创建一个 TXT 记录
+
+4.Download SSL Certificate
+
+5.保存证书(和上述相同)

+ 24 - 0
docs/deploy.md

@@ -0,0 +1,24 @@
+# 站点部署
+
+## 使用自己的 github.io
+
+1.进入 https://github.com/zjcqoo/zjcqoo.github.io 点击 fork。
+
+2.进入 Settings 页面,仓库重命名成 `my.github.io`(假设用户名为 `my`)
+
+3.进入 `conf.js` 文件,参考备注修改:
+
+* 节点列表(`node_map` 字段,包括节点 id 和节点主机)
+
+* 默认节点(`node_default` 字段,指定节点 id)
+
+4.访问 `https://my.github.io` 预览
+
+> 本项目支持子路径。仓库可重命名成任何名字(例如 x),然后创建 `gh-pages` 分支,通过 `https://用户名.github.io/x` 也能访问。
+
+
+## 使用任意站点
+
+访问浏览器端的项目:https://github.com/EtherDream/jsproxy-browser
+
+参考上述修改 `www` 目录中的 `conf.js`,然后发布 `www` 目录到网站即可。

+ 29 - 1
docs/compile.md → docs/setup.md

@@ -13,7 +13,7 @@ su - jsproxy
 
 
 非 Linux 系统,或者无 root 权限的设备,可忽略。
 非 Linux 系统,或者无 root 权限的设备,可忽略。
 
 
-> 为什么要创建用户?因为本服务无需 root,所以使用低权限减少风险。另外在防 SSRF 脚本 `setup-ipset.sh` 中,是通过 iptalbes 的 `uid-owner` 策略阻止 `jsprxoy` 这个特定用户访问内网的。
+> 为什么要创建用户?因为使用低权限运行服务可减少风险。另外在防 SSRF 脚本 `setup-ipset.sh` 中,是通过 iptalbes 的 `uid-owner` 策略阻止 `jsprxoy` 这个特定用户访问内网的。
 
 
 
 
 ## 安装 nginx
 ## 安装 nginx
@@ -81,6 +81,34 @@ cd server
 更新使用 git 即可。
 更新使用 git 即可。
 
 
 
 
+## 申请域名
+
+* 免费申请:https://www.freenom.com
+
+* 临时测试:`服务器IP.xip.io`
+
+类似的还有 `nip.io`、`sslip.io`,自动安装脚本默认使用 `xip.io`。
+
+
+## 申请证书
+
+可通过 Let's Encrypt 申请免费的 HTTPS 证书。
+
+* [手动申请](cert-manual.md)
+
+* [自动申请](cert-auto.md)
+
+也可以不申请证书,使用免费的 HTTPS 反向代理,例如 [CloudFlare](https://www.cloudflare.com/):
+
+```text
+[浏览器] --- https ---> [CloudFlare] --- http ---> [服务器]
+```
+
+这种方案不仅能节省系统资源,还能减少流量开销(静态资源可被 CloudFlare 缓存)。当然延时可能较高,并且安全性略低。
+
+> 为什么一定要用 HTTPS?因为本项目使用了浏览器 Service Worker 技术,该 API 只能在安全环境使用,除了 localhost、127.0.0.0/8 站点可以使用 HTTP,其他必须 HTTPS。
+
+
 ## 支持系统
 ## 支持系统
 
 
 目前测试了 OSX 系统,其他还在测试中。。。
 目前测试了 OSX 系统,其他还在测试中。。。

+ 0 - 1
nginx.conf

@@ -69,7 +69,6 @@ http {
   lua_load_resty_core     off;
   lua_load_resty_core     off;
 
 
   map $http_origin $_origin_id {
   map $http_origin $_origin_id {
-    ''                    'mysite';
     include               allowed-sites.conf;
     include               allowed-sites.conf;
   }
   }
 }
 }