Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ id_ed25519
# ------------------------------
# Build outputs
# ------------------------------
dist/
build/
.next/
.nuxt/
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ docker compose --profile nginx up -d
docker compose --profile openresty up -d
```

#### 卸载命令

```bash
docker compose --profile nginx down
# 或
docker compose --profile openresty down
```

#### 想让Nginx访问宿主机服务怎么办?

默认 Docker 部署使用 bridge 网络。此时容器内 Nginx/OpenResty 的 `127.0.0.1` 指向容器自身;反向代理其他容器应使用同一 Docker network 下的服务名,例如 `http://app:8080`。
Expand All @@ -218,6 +226,7 @@ docker compose --profile openresty up -d

```bash
curl -fsSLO https://raw.githubusercontent.com/luoye663/nxpanel/main/docker-compose.host.yml

docker compose -f docker-compose.yml -f docker-compose.host.yml --profile nginx up -d
```

Expand Down Expand Up @@ -245,6 +254,7 @@ https://服务器IP:18888/随机入口路径

适合接入已有 Nginx/OpenResty,或在已经完成 Nginx 安装后部署 NxPanel。在线安装会从 GitHub Releases 下载 `nxpanel-linux-amd64.tar.gz`。


```bash
# 安装脚本
curl -fsSL https://raw.githubusercontent.com/luoye663/nxpanel/main/install.sh | sudo bash
Expand All @@ -253,6 +263,10 @@ curl -fsSL https://raw.githubusercontent.com/luoye663/nxpanel/main/install.sh |
curl -fsSL https://raw.githubusercontent.com/luoye663/nxpanel/main/uninstall.sh | sudo bash
```

> 如果系统中已有 Nginx/OpenResty,那么在安装完 NxPanel 后,需要到 Nginx 管理页面,依次点击 检测 Nginx、安装 Include 入口 这2个按钮。

![图片.png](https://img.326333.xyz/i/f36433dFKiyMXiazqroHpkYAn.webp)

也可以下载 release 后在解压目录执行:

```bash
Expand Down
4 changes: 2 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1067,9 +1067,9 @@ show_completion() {
validate_login_path "$login_path" || login_path=""
local api_port=""
api_port=$(extract_listen_port "$API_LISTEN" || true)
echo "访问地址: https://IP:${api_port:-18888}/$login_path"
echo "访问地址: https://IP:${api_port:-18888}$login_path"
echo "TLS 证书: $DATA_DIR/data/tls/api.crt(自签名,浏览器会显示安全警告)"
echo "HTTP→HTTPS 重定向: :${api_port:-18888} → https://IP:${api_port:-18888}/$login_path"
echo "HTTP→HTTPS 重定向: :${api_port:-18888} → https://IP:${api_port:-18888}$login_path"
echo ""
echo "常用命令:"
echo " 查看日志: journalctl -u nxpanel-api -f"
Expand Down
130 changes: 130 additions & 0 deletions scripts/nginx-install/dist/apt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# ============================================================
# dist/apt.sh — Debian / Ubuntu 包安装适配器
#
# 聚焦发行版白名单(与 dist_validate_support 一致):
# debian:12、debian:13、ubuntu:22.04、ubuntu:24.04、ubuntu:26.04
#
# 实现 5 个 adapter 接口函数 + PKG_MANAGER 变量。
# repo/key 数据来自 runtime/<id>.sh,apt adapter 负责落盘。
#
# 依赖:lib/log.sh、lib/os.sh、lib/command.sh、lib/repo.sh、runtime/<id>.sh
# ============================================================

PKG_MANAGER="apt"

# dist_validate_support
# 用主版本号匹配,避免 OS 报告带小版本(如 24.04.1)时漏判。
dist_validate_support() {
case "${OS_ID}:${OS_VERSION_ID_MAJOR}" in
debian:12|debian:13|ubuntu:22|ubuntu:24|ubuntu:26)
return 0
;;
*)
die "apt 适配器不支持 ${OS_ID} ${OS_VERSION_ID}(聚焦:debian:12/13、ubuntu:22.04/24.04/26.04)"
;;
esac
}

# dist_install_prereqs
# 安装基础依赖;清理上次运行残留的 nginx.list / openresty.list(仅脚本自身创建的)。
dist_install_prereqs() {
log_step "安装前置依赖 (apt)..."

rm -f /etc/apt/sources.list.d/nginx.list
rm -f /etc/apt/sources.list.d/openresty.list

apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates curl gnupg lsb-release
}

# dist_add_repository
# 通过 runtime_* 拿 key URL / keyring 路径 / repo base;通过 resolve_codename 选 codename。
dist_add_repository() {
log_step "添加 ${RUNTIME_ID} 官方 APT 仓库..."

local keyring key_url repo_base codename
keyring=$(runtime_get_keyring_path)
key_url=$(runtime_get_repo_key_url)
repo_base=$(runtime_get_apt_repo_base)
codename=$(resolve_codename "$repo_base")

install -d -m 0755 "$(dirname "$keyring")"
if [ ! -f "$keyring" ]; then
download_to_pipe "$key_url" | gpg --dearmor -o "$keyring" 2>/dev/null
chmod 644 "$keyring"
fi

# runtime 决定 repo 行写法(signed-by / trusted 策略 + 组件名)
runtime_write_apt_repo "$repo_base" "$codename" "$keyring"

# runtime 决定是否写 priorities(nginx 写 99nginx;openresty no-op)
runtime_write_apt_preferences

# Debian 13 + OpenResty + 用户 opt-in:临时放宽 apt-sqv SHA1 策略
_maybe_apply_sha1_relax
}

# _cleanup_sha1_relax_policy
# 清理 _maybe_apply_sha1_relax 写的临时策略文件;best-effort 刷新 apt 缓存。
# 通过 register_cleanup_hook 在 EXIT/INT/TERM 时调用。
_cleanup_sha1_relax_policy() {
local policy_file=/etc/crypto-policies/back-ends/apt-sequoia.config
if [ -f "$policy_file" ]; then
rm -f "$policy_file"
log_info "已清理临时放宽的 SHA1 策略文件: $policy_file"
# 刷新 apt 缓存:OpenResty repo 在策略恢复后会再次报 SHA1 警告,属预期
if command -v apt-get >/dev/null 2>&1; then
apt-get update -qq 2>/dev/null || \
log_warn "恢复策略后 apt-get update 出现警告(OpenResty repo 报 SHA1 属预期)"
fi
fi
}

# _maybe_apply_sha1_relax
# 仅 Debian 13 + OpenResty + INSECURE_RELAX_SHA1=true 时生效。
# 写 /etc/crypto-policies/back-ends/apt-sequoia.config,注册清理钩子。
_maybe_apply_sha1_relax() {
if [ "${INSECURE_RELAX_SHA1:-false}" != "true" ]; then
return 0
fi
# 严格限定触发条件:避免误用
if [ "$OS_ID" != "debian" ] || [ "$OS_VERSION_ID_MAJOR" -lt 13 ]; then
return 0
fi
if [ "$RUNTIME_ID" != "openresty" ]; then
return 0
fi

local policy_file=/etc/crypto-policies/back-ends/apt-sequoia.config

log_warn "=============================================================="
log_warn " ⚠ 应用 SHA1 策略临时放宽(apt-sqv)"
log_warn "--------------------------------------------------------------"
log_warn " 原因:OpenResty 官方 key 的 binding signature 使用 SHA1,"
log_warn " Sequoia (apt-sqv) 在 Debian 13 默认拒绝。"
log_warn " 操作:写 $policy_file"
log_warn " 将 SHA1 second_preimage_resistance 截止延后到 2027-02-01。"
log_warn " ⚠ 该放宽作用于全系统 apt 仓库(不止 OpenResty)。"
log_warn " ⚠ 安装完成(或失败)后自动清理该文件。"
log_warn " ⚠ 后续 apt upgrade openresty 仍会再次失败,需重新跑本脚本。"
log_warn "=============================================================="

mkdir -p /etc/crypto-policies/back-ends
cat > "$policy_file" <<'EOF'
[hash_algorithms]
sha1.second_preimage_resistance = 2027-02-01
EOF

register_cleanup_hook _cleanup_sha1_relax_policy
}

# dist_refresh_cache
dist_refresh_cache() {
apt-get update -qq
}

# dist_install_packages <pkg...>
dist_install_packages() {
DEBIAN_FRONTEND=noninteractive apt-get install -y "$@"
}
59 changes: 59 additions & 0 deletions scripts/nginx-install/dist/dnf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# ============================================================
# dist/dnf.sh — AlmaLinux / Rocky / RHEL / CentOS 系 dnf 适配器
#
# 聚焦发行版白名单:
# almalinux:8、almalinux:9、alinux:3、rockylinux:9(容器内 OS_ID=rocky)
#
# 实现 5 个 adapter 接口函数 + PKG_MANAGER 变量。
# repo/key 数据来自 runtime/<id>.sh,dnf adapter 负责落盘。
#
# 依赖:lib/log.sh、lib/os.sh、lib/command.sh、lib/repo.sh、runtime/<id>.sh
# ============================================================

PKG_MANAGER="dnf"

# dist_validate_support
# 用主版本号匹配,避免 OS 报告带小版本(如 rocky 9.3)时漏判。
dist_validate_support() {
case "${OS_ID}:${OS_VERSION_ID_MAJOR}" in
almalinux:8|almalinux:9|alinux:3|rocky:9|rockylinux:9|ol:8|ol:9|opencloudos:9)
return 0
;;
*)
die "dnf 适配器不支持 ${OS_ID} ${OS_VERSION_ID}(聚焦:almalinux:8/9、alinux:3、rockylinux:9、oracle linux:8/9、opencloudos:9)"
;;
esac
}

# dist_install_prereqs
# el8/el9 用 curl-minimal 减少依赖;ca-certificates、gnupg2 是基础。
# --allowerasing:处理系统已装 curl 而我们装 curl-minimal 时的冲突(oracle/opencloudos 等预装 curl 全包)。
dist_install_prereqs() {
log_step "安装前置依赖 (dnf)..."

if [ "$OS_VERSION_ID_MAJOR" -ge 9 ]; then
dnf install -y --allowerasing ca-certificates curl-minimal gnupg2
else
dnf install -y ca-certificates curl gnupg2
fi
}

# dist_add_repository
# runtime 决定 repo 文件内容(nginx 内联生成 / openresty 下载官方 .repo)。
dist_add_repository() {
log_step "添加 ${RUNTIME_ID} 官方 YUM 仓库..."
runtime_write_yum_repo
}

# dist_refresh_cache
dist_refresh_cache() {
dnf makecache
}

# dist_install_packages <pkg...>
# --nobest:当最新版有未满足依赖时回退到可安装的旧版本。
# 例:OpenCloudOS 9 ships OpenSSL 3.0.x,最新 nginx 需要 OpenSSL 3.2.0+ ABI;
# --nobest 让 dnf 自动选可安装的较旧版本(如 1.28.x),避免硬失败。
dist_install_packages() {
dnf install -y --nobest "$@"
}
107 changes: 107 additions & 0 deletions scripts/nginx-install/dist/yum.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# ============================================================
# dist/yum.sh — CentOS 7 等 yum-only 发行版的包安装适配器
#
# 聚焦发行版:centos:7(其他 yum 发行版若有需要再扩展)
#
# CentOS 7 已于 2024-06-30 EOL,官方 mirrorlist.centos.org 已下线。
# 本 adapter 在 dist_install_prereqs 阶段自动检测并把 CentOS-Base.repo
# 重写为 vault.centos.org/7.9.2009/,确保 yum 能正常工作。
#
# 依赖:lib/log.sh、lib/os.sh、lib/command.sh、lib/repo.sh、runtime/<id>.sh
# ============================================================

PKG_MANAGER="yum"

# dist_validate_support
# 仅 centos:7;其他 yum 发行版暂未列入聚焦矩阵。
dist_validate_support() {
case "${OS_ID}:${OS_VERSION_ID_MAJOR}" in
centos:7)
return 0
;;
*)
die "yum 适配器不支持 ${OS_ID} ${OS_VERSION_ID}(聚焦:centos:7)"
;;
esac
}

# _fix_centos7_eol_base_repo
# CentOS 7 已 EOL,官方 mirrorlist.centos.org 关闭。检测到该情况时
# 把 /etc/yum.repos.d/CentOS-Base.repo 重写为 vault.centos.org/7.9.2009/。
# 仅当文件存在且仍指向 mirrorlist.centos.org 时才重写,尊重用户自定义。
_fix_centos7_eol_base_repo() {
if [ "$OS_ID" != "centos" ] || [ "$OS_VERSION_ID_MAJOR" != "7" ]; then
return 0
fi

local base_repo="/etc/yum.repos.d/CentOS-Base.repo"
if [ ! -f "$base_repo" ]; then
return 0
fi

# 仅在文件还含 mirrorlist.centos.org 时才重写(用户已改过则不动)
if ! grep -q "mirrorlist.centos.org" "$base_repo" 2>/dev/null; then
return 0
fi

log_warn "检测到 CentOS 7 EOL(mirrorlist.centos.org 已下线),自动切换到 vault.centos.org"

# 备份原文件
cp "$base_repo" "${base_repo}.bak.$(date +%Y%m%d%H%M%S)"

cat > "$base_repo" <<'EOF'
# CentOS-Base.repo - 重写为 vault.centos.org(CentOS 7 EOL by nxpanel installer)
[base]
name=CentOS-$releasever - Base
baseurl=https://vault.centos.org/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-$releasever - Updates
baseurl=https://vault.centos.org/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever - Extras
baseurl=https://vault.centos.org/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://vault.centos.org/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF

yum clean all >/dev/null 2>&1 || true
log_info "已重写 $base_repo → vault.centos.org/7.9.2009/"
}

# dist_install_prereqs
# 先修 EOL base repo,再装基础依赖。
dist_install_prereqs() {
log_step "安装前置依赖 (yum)..."
_fix_centos7_eol_base_repo
yum install -y ca-certificates curl gnupg2
}

# dist_add_repository
# runtime 决定 repo 文件内容(nginx 内联生成 / openresty 下载官方 .repo)。
dist_add_repository() {
log_step "添加 ${RUNTIME_ID} 官方 YUM 仓库..."
runtime_write_yum_repo
}

# dist_refresh_cache
dist_refresh_cache() {
yum makecache fast 2>/dev/null || yum makecache
}

# dist_install_packages <pkg...>
dist_install_packages() {
yum install -y "$@"
}
Loading