#!/usr/bin/env bash # # proxy-up.sh — 启动本机 nginx 反代 (dacli proxy up) # # 前置: brew install nginx (Intel Mac 路径 /usr/local/, ARM Mac 路径 /opt/homebrew/) # set -euo pipefail # 检测 brew nginx 路径 if command -v nginx >/dev/null; then : # nginx 已在 PATH elif [[ -x /usr/local/bin/nginx ]]; then export PATH="/usr/local/bin:$PATH" elif [[ -x /opt/homebrew/bin/nginx ]]; then export PATH="/opt/homebrew/bin:$PATH" else echo "nginx not found. Install: brew install nginx" >&2 exit 1 fi # 解析 brew prefix (兼容 Intel/ARM) BREW_PREFIX="$(brew --prefix 2>/dev/null || echo /usr/local)" SERVERS_DIR="${BREW_PREFIX}/etc/nginx/servers" SSW_CONF_SRC="$(cd "$(dirname "$0")/.." && pwd)/config/nginx/ssw.conf" mkdir -p "$SERVERS_DIR" ln -sf "$SSW_CONF_SRC" "$SERVERS_DIR/ssw.conf" if ! sudo nginx -t; then echo "nginx config test failed" >&2 exit 1 fi if pgrep -x nginx >/dev/null; then sudo nginx -s reload else sudo nginx fi echo "nginx up: http://nginx/" echo "verify: curl -fsS http://nginx/api/system/DbLink/List"