diff --git a/install.sh b/install.sh index 8dabd7c..af2bcde 100644 --- a/install.sh +++ b/install.sh @@ -1464,6 +1464,13 @@ deploy_acme_letsencrypt() { # 申请证书 echo "" print_info "正在申请 Let's Encrypt 证书..." + + # 再次确认acme.sh存在 + if [[ ! -f ~/.acme.sh/acme.sh ]]; then + print_error "acme.sh文件不存在: ~/.acme.sh/acme.sh" + return 1 + fi + if ~/.acme.sh/acme.sh --issue -d "$DOMAIN" --nginx; then print_success "证书申请成功" else @@ -1480,6 +1487,13 @@ deploy_acme_letsencrypt() { # 安装证书 echo "" print_info "正在安装证书到Nginx..." + + # 再次确认acme.sh存在 + if [[ ! -f ~/.acme.sh/acme.sh ]]; then + print_error "acme.sh文件不存在: ~/.acme.sh/acme.sh" + return 1 + fi + mkdir -p /etc/nginx/ssl if ~/.acme.sh/acme.sh --install-cert -d "$DOMAIN" \ --key-file /etc/nginx/ssl/${DOMAIN}.key \ @@ -1599,6 +1613,13 @@ deploy_acme_zerossl() { # 申请证书 echo "" print_info "正在申请 ZeroSSL 证书..." + + # 再次确认acme.sh存在 + if [[ ! -f ~/.acme.sh/acme.sh ]]; then + print_error "acme.sh文件不存在: ~/.acme.sh/acme.sh" + return 1 + fi + if ~/.acme.sh/acme.sh --server zerossl --issue -d "$DOMAIN" --nginx; then print_success "证书申请成功" else @@ -1609,6 +1630,13 @@ deploy_acme_zerossl() { # 安装证书 echo "" print_info "正在安装证书到Nginx..." + + # 再次确认acme.sh存在 + if [[ ! -f ~/.acme.sh/acme.sh ]]; then + print_error "acme.sh文件不存在: ~/.acme.sh/acme.sh" + return 1 + fi + mkdir -p /etc/nginx/ssl if ~/.acme.sh/acme.sh --install-cert -d "$DOMAIN" \ --key-file /etc/nginx/ssl/${DOMAIN}.key \ @@ -1728,6 +1756,13 @@ deploy_acme_buypass() { # 申请证书 echo "" print_info "正在申请 Buypass 证书..." + + # 再次确认acme.sh存在 + if [[ ! -f ~/.acme.sh/acme.sh ]]; then + print_error "acme.sh文件不存在: ~/.acme.sh/acme.sh" + return 1 + fi + if ~/.acme.sh/acme.sh --server buypass --issue -d "$DOMAIN" --nginx; then print_success "证书申请成功" else @@ -1738,6 +1773,13 @@ deploy_acme_buypass() { # 安装证书 echo "" print_info "正在安装证书到Nginx..." + + # 再次确认acme.sh存在 + if [[ ! -f ~/.acme.sh/acme.sh ]]; then + print_error "acme.sh文件不存在: ~/.acme.sh/acme.sh" + return 1 + fi + mkdir -p /etc/nginx/ssl if ~/.acme.sh/acme.sh --install-cert -d "$DOMAIN" \ --key-file /etc/nginx/ssl/${DOMAIN}.key \ @@ -2456,11 +2498,18 @@ configure_nginx_https() { mkdir -p ${NGINX_CONF_DIR} fi + # 根据HTTPS端口生成正确的重定向URL + if [[ "$HTTPS_PORT" == "443" ]]; then + REDIRECT_URL="https://\$server_name\$request_uri" + else + REDIRECT_URL="https://\$server_name:${HTTPS_PORT}\$request_uri" + fi + cat > ${NGINX_CONF_DIR}/${PROJECT_NAME}.conf << EOF server { listen ${HTTP_PORT}; server_name ${DOMAIN}; - return 301 https://\$server_name:\${HTTPS_PORT}\$request_uri; + return 301 ${REDIRECT_URL}; } server {