You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

更换域名重装SSL后Nginx站点显示空白页求助

问题描述

原本正常运行的WordPress网站更换域名时,需移除旧SSL证书并安装新证书,操作后访问新域名仅显示空白页,相关调试无日志输出,Wappalizer无法检测到WordPress存在。

服务器配置

  • Ubuntu 20.04
  • Nginx(最新版本)
  • MariaDb
  • php-fpm
  • WordPress

已执行操作

  1. 备份Let's Encrypt目录:cp -r /etc/letsencrypt/ /etc/letsencrypt.backup
  2. 吊销旧证书:certbot revoke --cert-path /etc/letsencypt/archive/healthwellnesssynergy.com/cert1.pem(注:命令路径拼写错误,letsencypt应为letsencrypt)
  3. 删除旧证书:certbot delete
  4. 彻底卸载Nginx:sudo apt purge nginx nginx-common nginx-core
  5. 重新安装Nginx,通过Certbot安装新SSL证书后重启Nginx

当前现象

  • 访问新域名hwscenter.com显示空白页
  • Nginx和MariaDb服务状态正常
  • Nginx日志无相关错误记录
  • 开启WordPress debug模式无反应
  • Wappalizer无法检测到WordPress存在

当前Nginx配置

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.php;

    server_name hwscenter.com;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php?$args;
    }

    # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
    #   include snippets/fastcgi-php.conf;
    #
    #   # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    #   # With php-cgi (or other tcp sockets):
    #   fastcgi_pass 127.0.0.1:9000;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/hwscenter.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/hwscenter.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#   listen 80;
#   listen [::]:80;
#
#   server_name example.com;
#
#   root /var/www/example.com;
#   index index.html;
#
#   location / {
#       try_files $uri $uri/ =404;
#   }
#}

server {
    if ($host = hwscenter.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 default_server;
    listen [::]:80 default_server;

    server_name hwscenter.com;
    return 404; # managed by Certbot


}
问题排查与解决建议
  • 补全Nginx FastCGI核心配置:你的PHP location块注释掉了include snippets/fastcgi-php.conf;,这个文件包含了Nginx传递请求给PHP-FPM的关键参数(比如fastcgi_param SCRIPT_FILENAME),缺失会导致PHP脚本无法被正确解析。取消注释后重启Nginx:

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }
    
  • 验证PHP-FPM状态与版本匹配:执行systemctl status php7.4-fpm确认服务是否正常运行,未启动则执行systemctl start php7.4-fpm。同时确保WordPress目录使用的PHP版本与FPM版本一致,避免版本不兼容。

  • 更新WordPress站点域名配置:更换域名后需同步修改WordPress数据库中的站点地址:

    1. 登录MariaDb:mysql -u root -p
    2. 切换至WordPress数据库:use 你的WordPress数据库名;
    3. 更新站点地址:UPDATE wp_options SET option_value = 'https://hwscenter.com' WHERE option_name = 'siteurl';
    4. 更新首页地址:UPDATE wp_options SET option_value = 'https://hwscenter.com' WHERE option_name = 'home';
      (注:若你的表前缀不是wp_,替换为实际前缀)
  • 修复文件权限:卸载重装Nginx可能导致/var/www/html目录权限异常,执行以下命令修复:

    sudo chown -R www-data:www-data /var/www/html
    sudo find /var/www/html -type d -exec chmod 755 {} \;
    sudo find /var/www/html -type f -exec chmod 644 {} \;
    
  • 查看PHP错误日志:Nginx无日志不代表PHP无错误,查看/var/log/php7.4-fpm.log,这里会记录PHP执行时的静默错误,帮助定位问题。

  • 修正旧证书吊销命令拼写:之前执行的certbot revoke命令路径存在拼写错误(letsencypt少了字母r),后续若需使用备份目录需注意此问题。

内容的提问来源于stack exchange,提问作者Emperial

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 01:10:29