mirror of
https://github.com/EtherDream/jsproxy
synced 2024-11-21 17:37:58 +00:00
更新安装脚本
This commit is contained in:
parent
461b00b6b3
commit
1fae695493
103
README.md
103
README.md
@ -4,62 +4,52 @@ https://zjcqoo.github.io/-----https://www.google.com
|
||||
|
||||
(由于访问量较大,目前限制 Referer 只允许从 GitHub 访问)
|
||||
|
||||
```bash
|
||||
curl -O https://raw.githubusercontent.com/EtherDream/jsproxy/master/i.sh && bash i.sh
|
||||
```
|
||||
|
||||
# 一键安装
|
||||
如果安装失败,尝试[源码编译安装](docs/compile.md)。
|
||||
|
||||
|
||||
# 测试
|
||||
|
||||
可通过如下命令,验证代理是否生效:
|
||||
|
||||
```bash
|
||||
curl http://服务器IP:8080/http \
|
||||
-H '--url: https://git.io/fj85d' \
|
||||
-H 'Origin: http://localhost'
|
||||
```
|
||||
|
||||
正常情况下,显示 `ok`。如果无法连接,检查 8080/8443 端口是否添加到防火墙。
|
||||
|
||||
其他错误,可尝试查看错误日志:
|
||||
|
||||
```bash
|
||||
cat /home/jsproxy/server/nginx/logs/error.log
|
||||
```
|
||||
|
||||
|
||||
# 维护
|
||||
|
||||
```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
|
||||
# 切换到 jsproxy 用户
|
||||
su - jsproxy
|
||||
|
||||
git clone --depth=1 https://github.com/EtherDream/jsproxy.git server
|
||||
# 重启服务
|
||||
./run.sh reload
|
||||
|
||||
cd server
|
||||
./setup-nginx.sh
|
||||
# 关闭服务(参数和 nginx -s 相同)
|
||||
./run.sh quit
|
||||
|
||||
# 启动服务
|
||||
./run.sh
|
||||
|
||||
# 查看代理日志
|
||||
tail server/nginx/logs/proxy.log
|
||||
```
|
||||
|
||||
安装过程若有依赖缺失,可尝试(CentOS 为例):
|
||||
|
||||
```bash
|
||||
yum install -y \
|
||||
gcc gcc-c++ \
|
||||
pcre pcre-devel \
|
||||
openssl openssl-devel \
|
||||
zlib zlib-devel
|
||||
```
|
||||
|
||||
> nginx 最终安装在 `/home/jsproxy/openresty` 下,不会和系统已有的冲突。
|
||||
|
||||
启动服务:
|
||||
|
||||
```bash
|
||||
~/server/run.sh
|
||||
```
|
||||
|
||||
# 本地测试
|
||||
|
||||
在浏览器中测试 127.0.0.1:8080 服务是否正常运行:
|
||||
|
||||
https://zjcqoo.github.io/#local
|
||||
|
||||
![](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`,有些地区很慢)
|
||||
|
||||
注意,**当前项目只提供接口服务**,浏览器端脚本和页面不在本项目。这样做是为了让接口和界面分离,意义参见后续。
|
||||
目前暂未实现开机自启动。
|
||||
|
||||
|
||||
# 远程测试
|
||||
@ -107,20 +97,17 @@ https://myhost.github.io 'my';
|
||||
|
||||
# 安全策略
|
||||
|
||||
如果不希望代理访问内网,可执行 `setup-ipset.sh`,避免 SSRF 风险。
|
||||
如果不希望代理访问内网,可执行 `setup-ipset.sh` 避免 SSRF 风险:
|
||||
|
||||
```bash
|
||||
/home/jsproxy/setup-ipset.sh
|
||||
```
|
||||
|
||||
> 需要 root 权限,依赖 `ipset` 命令
|
||||
|
||||
该脚本可禁止 `jsporxy` 用户访问内网(针对 TCP)。nginx 之外的程序也生效,但不影响其他用户。
|
||||
|
||||
|
||||
# 服务管理
|
||||
|
||||
重启服务:`./run.sh reload`
|
||||
|
||||
关闭服务:`./run.sh quit`
|
||||
|
||||
参数和 nginx -s 相同。
|
||||
|
||||
|
||||
# 项目特点
|
||||
|
||||
相比传统在线代理,本项目具有以下特点:
|
||||
|
194
i.sh
Normal file → Executable file
194
i.sh
Normal file → Executable file
@ -1,13 +1,189 @@
|
||||
#!/usr/bin/env sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SRC=https://raw.githubusercontent.com/EtherDream/jsproxy-bin/master/setup.sh
|
||||
DST=/home/jsproxy/setup.sh
|
||||
CDN=https://cdn.jsdelivr.net/gh/etherdream/jsproxy-bin@master
|
||||
|
||||
groupadd nobody
|
||||
useradd jsproxy -g nobody --create-home
|
||||
JSPROXY_VER=0.0.2
|
||||
PCRE_VER=8.43
|
||||
ZLIB_VER=1.2.11
|
||||
OPENSSL_VER=1.1.1b
|
||||
OPENRESTY_VER=1.15.8.1
|
||||
|
||||
echo "download main script ..."
|
||||
curl -s $SRC -o $DST
|
||||
SUPPORTED_OS="Linux-x86_64"
|
||||
OS="$(uname)-$(uname -m)"
|
||||
|
||||
chmod +x $DST
|
||||
su - jsproxy -c $DST
|
||||
NGX_DIR="$HOME/openresty"
|
||||
|
||||
COLOR_RESET="\033[0m"
|
||||
COLOR_RED="\033[31m"
|
||||
COLOR_GREEN="\033[32m"
|
||||
COLOR_YELLOW="\033[33m"
|
||||
|
||||
output() {
|
||||
color=$1
|
||||
shift 1
|
||||
sdata="$@"
|
||||
stime=$(date "+%H:%M:%S")
|
||||
printf "$color[jsproxy $stime]$COLOR_RESET $sdata\n"
|
||||
}
|
||||
log() {
|
||||
output $COLOR_GREEN $1
|
||||
}
|
||||
warn() {
|
||||
output $COLOR_YELLOW $1
|
||||
}
|
||||
err() {
|
||||
output $COLOR_RED $1
|
||||
}
|
||||
|
||||
check_nginx() {
|
||||
NGX_EXE="$NGX_DIR/nginx/sbin/nginx"
|
||||
NGX_VER=$($NGX_EXE -v 2>&1)
|
||||
|
||||
if [[ "$NGX_VER" != *"nginx version:"* ]]; then
|
||||
err "$NGX_EXE 无法执行!尝试编译安装"
|
||||
exit 1
|
||||
fi
|
||||
log "nginx 安装完成。$NGX_VER"
|
||||
}
|
||||
|
||||
install_jsproxy() {
|
||||
log "下载 jsproxy ..."
|
||||
curl -s -O $CDN/server-$JSPROXY_VER.tar.gz
|
||||
|
||||
if [ -d "server" ]; then
|
||||
backup="bak/$(date +%Y_%m_%d_%H_%M_%S)"
|
||||
warn "当前 server 目录备份到 $backup"
|
||||
mkdir -p $backup
|
||||
mv server $backup
|
||||
fi
|
||||
|
||||
tar zxf server-$JSPROXY_VER.tar.gz
|
||||
rm -f server-$JSPROXY_VER.tar.gz
|
||||
|
||||
log "启动服务 ..."
|
||||
./server/run.sh
|
||||
|
||||
log "检测状态 ..."
|
||||
RET=$(curl -s http://127.0.0.1:8080/)
|
||||
|
||||
ERR_LOG=$PWD/server/logs/error.log
|
||||
|
||||
if [[ "$RET" != *"origin"* ]]; then
|
||||
err "服务启动异常。错误日志:"
|
||||
tail $ERR_LOG -n100
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "服务已开启。后续维护参考 https://github.com/EtherDream/jsproxy"
|
||||
}
|
||||
|
||||
compile() {
|
||||
TMP_DIR="$PWD/__tmp__"
|
||||
|
||||
mkdir -p $TMP_DIR
|
||||
cd $TMP_DIR
|
||||
|
||||
log "下载 pcre 源码 ..."
|
||||
curl -O https://ftp.pcre.org/pub/pcre/pcre-$PCRE_VER.tar.gz
|
||||
tar zxf pcre-$PCRE_VER.tar.gz
|
||||
|
||||
log "下载 zlib 源码 ..."
|
||||
curl -O https://zlib.net/zlib-$ZLIB_VER.tar.gz
|
||||
tar zxf zlib-$ZLIB_VER.tar.gz
|
||||
|
||||
log "下载 openssl 源码 ..."
|
||||
curl -O https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz
|
||||
tar zxf openssl-$OPENSSL_VER.tar.gz
|
||||
|
||||
log "下载 nginx 源码 ..."
|
||||
curl -O https://openresty.org/download/openresty-$OPENRESTY_VER.tar.gz
|
||||
tar zxf openresty-$OPENRESTY_VER.tar.gz
|
||||
|
||||
cd openresty-$OPENRESTY_VER
|
||||
|
||||
export PATH=$PATH:/sbin
|
||||
|
||||
log "配置中 ..."
|
||||
./configure \
|
||||
--with-openssl=../openssl-$OPENSSL_VER \
|
||||
--with-pcre=../pcre-$PCRE_VER \
|
||||
--with-zlib=../zlib-$ZLIB_VER \
|
||||
--with-http_v2_module \
|
||||
--with-http_ssl_module \
|
||||
--with-pcre-jit \
|
||||
--prefix=$NGX_DIR
|
||||
|
||||
log "编译中 ..."
|
||||
make
|
||||
make install
|
||||
|
||||
log "编译完成"
|
||||
rm -rf $TMP_DIR
|
||||
|
||||
check_nginx
|
||||
install_jsproxy
|
||||
}
|
||||
|
||||
install() {
|
||||
log "下载 nginx 程序 ..."
|
||||
curl -O $CDN/$OS/openresty-$OPENRESTY_VER.tar.gz
|
||||
tar zxf openresty-$OPENRESTY_VER.tar.gz
|
||||
rm -f openresty-$OPENRESTY_VER.tar.gz
|
||||
|
||||
check_nginx
|
||||
install_jsproxy
|
||||
}
|
||||
|
||||
update() {
|
||||
if [ ! -d "server" ]; then
|
||||
err "当前不存在 server 目录,切换到主目录再更新"
|
||||
exit 1
|
||||
fi
|
||||
install_jsproxy
|
||||
}
|
||||
|
||||
pack() {
|
||||
log "压缩 openresty ..."
|
||||
GZIP=-9
|
||||
tar cvzf openresty.tar.gz openresty
|
||||
}
|
||||
|
||||
main() {
|
||||
if [[ "$SUPPORTED_OS" != *"$OS"* ]]; then
|
||||
err "当前系统 $OS 不支持自动安装。尝试编译安装"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$USER" != "root" ]]; then
|
||||
err "自动安装需要 root 权限。如果无法使用 root,尝试编译安装"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "创建用户 jsproxy ..."
|
||||
groupadd nobody
|
||||
useradd jsproxy -g nobody --create-home
|
||||
|
||||
log "当前脚本移动到 $dst"
|
||||
src=$0
|
||||
dst=/home/jsproxy/i.sh
|
||||
|
||||
mv -f $src $dst
|
||||
chmod +x $dst
|
||||
|
||||
log "切换用户 jsproxy,执行安装脚本 ..."
|
||||
su - jsproxy -c "$dst install"
|
||||
}
|
||||
|
||||
|
||||
case "$1" in
|
||||
"install") install
|
||||
exit;;
|
||||
"compile") compile
|
||||
exit;;
|
||||
"pack") pack
|
||||
exit;;
|
||||
"update") update
|
||||
exit;;
|
||||
*) main
|
||||
exit;;
|
||||
esac
|
@ -1,18 +0,0 @@
|
||||
# 无需 root 运行
|
||||
curl -O https://openresty.org/download/openresty-1.15.8.1rc2.tar.gz
|
||||
tar zxvf openresty-*
|
||||
cd openresty-*
|
||||
|
||||
export PATH=$PATH:/sbin
|
||||
|
||||
./configure \
|
||||
--with-http_v2_module \
|
||||
--with-http_ssl_module \
|
||||
--with-pcre-jit \
|
||||
--prefix=/home/jsproxy/openresty
|
||||
|
||||
make
|
||||
make install
|
||||
|
||||
cd ..
|
||||
rm -rf openresty-*
|
Loading…
Reference in New Issue
Block a user