Ubuntu系统NGINX环境下WordPress后台wp-admin无法访问问题求助
问题排查与解决方案
根因分析
当前NGINX配置存在两处直接导致wp-admin无法访问的问题:
- 单独配置的
location /wp-admin块仅声明了index文件,没有配置请求转发规则,也没有匹配php文件的处理逻辑,所有wp-admin路径下的请求都无法被传递给PHP-FPM处理 - 现有重写规则仅匹配
/wp-admin结尾的路径,未覆盖wp-admin下的子路径请求,且未和php处理逻辑联动
修复步骤
1. 修改NGINX配置
删除冗余的location /wp-admin块和单独的rewrite规则,新增wp-admin专属路径适配规则,完整的server块参考配置如下:
server { listen 80; root /home/nicho/projects/strongbee-web-3.0; index index.php index.html index.htm index.nginx-debian.html; server_name _; location ~* \.(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|wml|swf|ttf|ttc|otf|eot|woff|woff2)$ { expires max; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; } location / { try_files $uri $uri/ /index.php?$args; } # 新增wp-admin路径适配规则 location /wp-admin/ { try_files $uri $uri/ /wp-admin/index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ /\.ht { deny all; } }
2. 校验配置并重启服务
执行命令校验NGINX配置是否合法:nginx -t
确认返回syntax is ok和test is successful后,重启NGINX服务生效:systemctl restart nginx
3. 兜底校验(若上述操作后仍无法访问)
检查WordPress根目录下的wp-config.php文件,确认以下配置和你实际访问的站点地址完全一致,不要出现http/https混用、多余后缀的情况:
define( 'WP_HOME', 'http://你的站点域名或IP' ); define( 'WP_SITEURL', 'http://你的站点域名或IP' );
内容的提问来源于stack exchange,提问作者NICHOLAS ANTONIUS
相关产品推荐
相关产品推荐

