fix: 修复Nginx配置目录兼容性,确保sites-available目录存在
问题: - Ubuntu 22.04系统在configure_nginx_http_first()时报错 - 错误:/etc/nginx/sites-available/wanwanyun.conf: No such file or directory - 原因:部分Ubuntu/Debian系统Nginx安装后未自动创建sites-available目录 修复: 1. 在所有Nginx配置函数中添加目录检测和创建逻辑 2. 使用mkdir -p确保目录存在后再写入配置文件 3. 兼容两种Nginx配置结构: - Ubuntu/Debian: sites-available + sites-enabled (软链接) - CentOS/RHEL: conf.d (直接加载.conf文件) 4. 根据PKG_MANAGER变量判断系统类型(更可靠) 修复的函数: - configure_nginx_http_first() - 两阶段部署的第一步 - configure_nginx_http() - HTTP模式配置 - configure_nginx_https() - HTTPS模式配置 预期效果: - Ubuntu/Debian系统:自动创建sites-available和sites-enabled目录 - CentOS/RHEL系统:使用conf.d目录 - 不再因为目录不存在而部署失败 相关错误: line 1964: /etc/nginx/sites-available/wanwanyun.conf: No such file or directory
This commit is contained in:
101
install.sh
101
install.sh
@@ -1961,7 +1961,27 @@ configure_nginx_http_first() {
|
||||
# 总是先配置HTTP模式
|
||||
local server_name="${DOMAIN:-_}"
|
||||
|
||||
cat > /etc/nginx/sites-available/${PROJECT_NAME}.conf << EOF
|
||||
# 检测Nginx配置目录结构并创建必要的目录
|
||||
if [[ -d /etc/nginx/sites-available ]] || [[ "$PKG_MANAGER" == "apt" ]]; then
|
||||
# Debian/Ubuntu: 使用sites-available
|
||||
NGINX_CONF_DIR="/etc/nginx/sites-available"
|
||||
NGINX_ENABLED_DIR="/etc/nginx/sites-enabled"
|
||||
USE_SYMLINK=true
|
||||
|
||||
# 确保目录存在
|
||||
mkdir -p ${NGINX_CONF_DIR}
|
||||
mkdir -p ${NGINX_ENABLED_DIR}
|
||||
else
|
||||
# CentOS/RHEL: 使用conf.d
|
||||
NGINX_CONF_DIR="/etc/nginx/conf.d"
|
||||
NGINX_ENABLED_DIR=""
|
||||
USE_SYMLINK=false
|
||||
|
||||
# 确保目录存在
|
||||
mkdir -p ${NGINX_CONF_DIR}
|
||||
fi
|
||||
|
||||
cat > ${NGINX_CONF_DIR}/${PROJECT_NAME}.conf << EOF
|
||||
server {
|
||||
listen ${HTTP_PORT};
|
||||
server_name ${server_name};
|
||||
@@ -2016,11 +2036,16 @@ server {
|
||||
}
|
||||
EOF
|
||||
|
||||
# 创建软链接
|
||||
ln -sf /etc/nginx/sites-available/${PROJECT_NAME}.conf /etc/nginx/sites-enabled/${PROJECT_NAME}.conf
|
||||
|
||||
# 删除默认站点
|
||||
rm -f /etc/nginx/sites-enabled/default
|
||||
# 根据系统类型处理配置文件
|
||||
if [[ "$USE_SYMLINK" == "true" ]]; then
|
||||
# Debian/Ubuntu: 创建软链接
|
||||
ln -sf ${NGINX_CONF_DIR}/${PROJECT_NAME}.conf ${NGINX_ENABLED_DIR}/${PROJECT_NAME}.conf
|
||||
# 删除默认站点
|
||||
rm -f ${NGINX_ENABLED_DIR}/default
|
||||
else
|
||||
# CentOS/RHEL: conf.d中的.conf文件会自动加载,删除默认配置
|
||||
rm -f /etc/nginx/conf.d/default.conf
|
||||
fi
|
||||
|
||||
# 测试nginx配置
|
||||
if ! nginx -t; then
|
||||
@@ -2106,7 +2131,22 @@ configure_nginx() {
|
||||
configure_nginx_http() {
|
||||
local server_name="${DOMAIN:-_}"
|
||||
|
||||
cat > /etc/nginx/sites-available/${PROJECT_NAME}.conf << EOF
|
||||
# 检测Nginx配置目录结构并创建必要的目录
|
||||
if [[ -d /etc/nginx/sites-available ]] || [[ "$PKG_MANAGER" == "apt" ]]; then
|
||||
# Debian/Ubuntu: 使用sites-available
|
||||
NGINX_CONF_DIR="/etc/nginx/sites-available"
|
||||
NGINX_ENABLED_DIR="/etc/nginx/sites-enabled"
|
||||
USE_SYMLINK=true
|
||||
mkdir -p ${NGINX_CONF_DIR}
|
||||
mkdir -p ${NGINX_ENABLED_DIR}
|
||||
else
|
||||
# CentOS/RHEL: 使用conf.d
|
||||
NGINX_CONF_DIR="/etc/nginx/conf.d"
|
||||
USE_SYMLINK=false
|
||||
mkdir -p ${NGINX_CONF_DIR}
|
||||
fi
|
||||
|
||||
cat > ${NGINX_CONF_DIR}/${PROJECT_NAME}.conf << EOF
|
||||
server {
|
||||
listen ${HTTP_PORT};
|
||||
server_name ${server_name};
|
||||
@@ -2161,15 +2201,35 @@ server {
|
||||
}
|
||||
EOF
|
||||
|
||||
# 创建软链接
|
||||
ln -sf /etc/nginx/sites-available/${PROJECT_NAME}.conf /etc/nginx/sites-enabled/${PROJECT_NAME}.conf
|
||||
|
||||
# 删除默认站点
|
||||
rm -f /etc/nginx/sites-enabled/default
|
||||
# 根据系统类型处理配置文件
|
||||
if [[ "$USE_SYMLINK" == "true" ]]; then
|
||||
# Debian/Ubuntu: 创建软链接
|
||||
ln -sf ${NGINX_CONF_DIR}/${PROJECT_NAME}.conf ${NGINX_ENABLED_DIR}/${PROJECT_NAME}.conf
|
||||
# 删除默认站点
|
||||
rm -f ${NGINX_ENABLED_DIR}/default
|
||||
else
|
||||
# CentOS/RHEL: conf.d中的.conf文件会自动加载
|
||||
rm -f /etc/nginx/conf.d/default.conf
|
||||
fi
|
||||
}
|
||||
|
||||
configure_nginx_https() {
|
||||
cat > /etc/nginx/sites-available/${PROJECT_NAME}.conf << EOF
|
||||
# 检测Nginx配置目录结构并创建必要的目录
|
||||
if [[ -d /etc/nginx/sites-available ]] || [[ "$PKG_MANAGER" == "apt" ]]; then
|
||||
# Debian/Ubuntu: 使用sites-available
|
||||
NGINX_CONF_DIR="/etc/nginx/sites-available"
|
||||
NGINX_ENABLED_DIR="/etc/nginx/sites-enabled"
|
||||
USE_SYMLINK=true
|
||||
mkdir -p ${NGINX_CONF_DIR}
|
||||
mkdir -p ${NGINX_ENABLED_DIR}
|
||||
else
|
||||
# CentOS/RHEL: 使用conf.d
|
||||
NGINX_CONF_DIR="/etc/nginx/conf.d"
|
||||
USE_SYMLINK=false
|
||||
mkdir -p ${NGINX_CONF_DIR}
|
||||
fi
|
||||
|
||||
cat > ${NGINX_CONF_DIR}/${PROJECT_NAME}.conf << EOF
|
||||
server {
|
||||
listen ${HTTP_PORT};
|
||||
server_name ${DOMAIN};
|
||||
@@ -2237,11 +2297,16 @@ server {
|
||||
}
|
||||
EOF
|
||||
|
||||
# 创建软链接
|
||||
ln -sf /etc/nginx/sites-available/${PROJECT_NAME}.conf /etc/nginx/sites-enabled/${PROJECT_NAME}.conf
|
||||
|
||||
# 删除默认站点
|
||||
rm -f /etc/nginx/sites-enabled/default
|
||||
# 根据系统类型处理配置文件
|
||||
if [[ "$USE_SYMLINK" == "true" ]]; then
|
||||
# Debian/Ubuntu: 创建软链接
|
||||
ln -sf ${NGINX_CONF_DIR}/${PROJECT_NAME}.conf ${NGINX_ENABLED_DIR}/${PROJECT_NAME}.conf
|
||||
# 删除默认站点
|
||||
rm -f ${NGINX_ENABLED_DIR}/default
|
||||
else
|
||||
# CentOS/RHEL: conf.d中的.conf文件会自动加载
|
||||
rm -f /etc/nginx/conf.d/default.conf
|
||||
fi
|
||||
}
|
||||
|
||||
start_backend_service() {
|
||||
|
||||
Reference in New Issue
Block a user