持续集成:部署脚本集成免root用户级Nginx自动启停与反向代理

This commit is contained in:
wangzhibiao committed 2026-09-14 13:02:41 +08:00
1 parent bd2d5b03c3
commit aa2b7d51ce
1 file changed
+61 -2
+61 -2
View File
@@ -65,9 +65,68 @@ for i in {1..35}; do
RES=$(curl -s "http://127.0.0.1:${SERVER_PORT}/captchaImage" 2>/dev/null)
if echo "$RES" | grep -q '"code":200'; then
echo "后端健康检查通过!验证码接口返回正常!服务已在端口 $SERVER_PORT 成功运行!"
exit 0
break
fi
sleep 2
done
echo "后端启动中或未在预期时间内完成自检,请检查日志: tail -n 50 $LOG_PATH"
echo "=== 3. 检查并启动/重载前端 Web 服务 (Nginx 8082) ==="
NGINX_DIR="$DEPLOY_ROOT/nginx"
NGINX_CONF="$NGINX_DIR/nginx.conf"
mkdir -p "$NGINX_DIR/temp"
if [ ! -f "$NGINX_CONF" ]; then
cat << 'NGINX_EOF' > "$NGINX_CONF"
pid /data2/wzb/deploy/nginx/nginx.pid;
error_log /data2/wzb/deploy/nginx/error.log;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
client_body_temp_path /data2/wzb/deploy/nginx/temp/client_body;
proxy_temp_path /data2/wzb/deploy/nginx/temp/proxy;
fastcgi_temp_path /data2/wzb/deploy/nginx/temp/fastcgi;
uwsgi_temp_path /data2/wzb/deploy/nginx/temp/uwsgi;
scgi_temp_path /data2/wzb/deploy/nginx/temp/scgi;
access_log /data2/wzb/deploy/nginx/access.log;
sendfile on;
keepalive_timeout 65;
server {
listen 8082;
server_name localhost;
location / {
root /data2/wzb/deploy/frontend;
try_files $uri $uri/ /index.html;
index index.html;
}
location /prod-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8092/;
}
}
}
NGINX_EOF
fi
if pgrep -u $(whoami) -f "nginx: master" >/dev/null; then
echo "平滑重载前端 Nginx 服务..."
/usr/sbin/nginx -c "$NGINX_CONF" -s reload
else
echo "启动前端 Nginx 服务..."
/usr/sbin/nginx -c "$NGINX_CONF"
fi
echo "=== 部署全部就绪!前端访问地址: http://192.168.139.230:8082 ==="