2 parents 8a3fb1d + a73cb9d commit d852118Copy full SHA for d852118
5 files changed
api.conf
@@ -1,12 +1,3 @@
1
-if ($_origin_id = '') {
2
- return 403 'ERROR: origin `$http_origin` is not allowed';
3
-}
4
-if ($http_x_jsproxy) {
5
- return 500 'ERROR: circular dependency';
6
7
-proxy_set_header x-jsproxy 1;
8
-proxy_set_header Connection $http_connection;
9
-
10
set $_level '';
11
set $_switched '';
12
set $_url '';
@@ -16,6 +7,20 @@ set $_type '';
16
set $_mode '';
17
set $_bodyhash '';
18
+error_page 500 502 504 /error;
+
+location = /error {
13
+ internal;
14
+ access_log off;
15
+ more_set_headers
+ 'access-control-allow-origin: *'
+ 'access-control-expose-headers: gateway-err--'
+ 'gateway-err--: {"msg": "$arg_msg", "addr": "$upstream_addr"}'
19
+ ;
20
+ return 200;
21
+}
22
23
24
location = /preflight {
25
internal;
26
access_log off;
@@ -31,8 +36,19 @@ location = /preflight {
31
36
32
37
# HTTP(S) Proxy
33
38
location = /http {
39
+ # see ./allowed-sites.conf
40
+ if ($_origin_id = '') {
41
+ rewrite ^ /error?msg=ORIGIN_NOT_ALLOWED;
42
+ }
43
+ if ($http_x_jsproxy) {
44
+ rewrite ^ /error?msg=CIRCULAR_DEPENDENCY;
45
46
+ proxy_set_header x-jsproxy 1;
47
+ proxy_set_header Connection $http_connection;
48
49
34
50
if ($http_access_control_request_headers) {
35
- rewrite ^ /preflight;
51
+ rewrite ^ /preflight;
52
}
53
54
access_by_lua_file ../lua/http-dec-req-hdr.lua;
i.sh
@@ -57,7 +57,7 @@ gen_cert() {
57
ip=$(curl -s $i)
58
59
if [[ ! $ip ]]; then
60
- warn "获取失败"
+ warn "获取失败"
61
continue
62
fi
63
@@ -179,7 +179,7 @@ install() {
179
180
181
if [ -d server ]; then
182
- backup="$INSTALL_DIR/bak/$(date +%Y_%m_%d_%H_%M_%S)"
+ localbackup="$INSTALL_DIR/bak/$(date +%Y_%m_%d_%H_%M_%S)"
183
warn "当前 server 目录备份到 $backup"
184
mkdir -p $backup
185
mv server $backup
log-svc/backup.sh
@@ -3,12 +3,13 @@
SVC_DIR=/home/jsproxy/server
LOG_DIR=$SVC_DIR/nginx/logs
+DST_DIR=$SVC_DIR/log-svc/backup
LOG_FILE=$LOG_DIR/proxy.log
-LOG_SIZE=$(( 32 * 1024 * 1024 ))
+LOG_SIZE=$(( 256 * 1024 * 1024 ))
ERR_FILE=$LOG_DIR/error.log
-ERR_SIZE=$(( 1*1024 * 1024 * 1024 ))
+ERR_SIZE=$(( 256 * 1024 * 1024 ))
# error.log 达到 ERR_SIZE,开始备份(目前只清理)
@@ -24,24 +25,21 @@ if (( $logsize < $LOG_SIZE )); then
27
logtime=$(date "+%Y-%m-%d-%H-%M-%S")
-logfile=$SVC_DIR/log-svc/backup/$logtime.log
28
29
#
30
# 先移走日志文件,然后创建新的日志文件,通知 nginx 重新打开
-mv $LOG_FILE $logfile
+mv $LOG_FILE $DST_DIR/$logtime.log
touch $LOG_FILE
$SVC_DIR/run.sh reopen
sleep 1
# 日志压缩
# 根据实际情况调整策略,在不影响系统的前提下,充分利用剩余 CPU
-# 可尝试其他工具(例如 7z),在开销和效果之间找一个平衡点
-echo "compress $logtime ($logsize bytes)"
+echo "compress ..."
-nice -n 19 \
- gzip $logfile
+nice -n 19 xz $DST_DIR/*.log
echo "done"
lua/http-enc-res-hdr.lua
@@ -23,17 +23,27 @@ end
local function flushHdr()
if detail then
- expose = expose .. ',--s'
+ if status ~= 200 then
+ expose = expose .. ',--s'
+ end
-- 该字段不在 aceh 中,如果浏览器能读取到,说明支持 * 通配
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
- ngx.header['--s'] = status
+ local status = ngx.status
+ -- 前端优先使用该字段作为状态码
+ ngx.header['--s'] = status
+ -- 保留原始状态码,便于控制台调试
+ -- 例如 404 显示红色,如果统一设置成 200 则没有颜色区分
+ -- 需要转义 30X 重定向,否则不符合 cors 标准
if
status == 301 or
status == 302 or
@@ -112,9 +122,9 @@ local function nodeSwitched()
112
122
113
123
114
124
-- 节点切换功能,目前还在测试中(demo 中已开启)
115
---if nodeSwitched() then
116
--- return
117
---end
125
+if nodeSwitched() then
126
+ return
127
+end
118
128
119
129
120
130
local h, err = ngx.resp.get_headers()
nginx.conf
@@ -45,7 +45,9 @@ http {
proxy_buffer_size 16k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
- proxy_send_timeout 10s;
+ proxy_send_timeout 30s;
+ proxy_read_timeout 30s;
+ proxy_connect_timeout 10s;
lua_load_resty_core off;
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments