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

Ubuntu环境下如何将已安装的WordPress接入Nginx?配置求助

问题:WordPress站点PHP文件被下载而非解析(Nginx配置问题)

背景

我在Vultr上部署了搭载WordPress的Ubuntu服务器,此前因问题卸载了Nginx和Certbot,执行命令:

$ sudo apt purge nginx
$ sudo apt purge certbot

重装并配置域名SSL后,访问域名显示Nginx欢迎页,/etc/nginx/conf.d目录下仅有default.conf文件。

当前Nginx配置(default.conf)

server {
    server_name  my.domain;

    #access_log  /var/log/nginx/host.access.log  main;

   
    location / {
      root /usr/share/nginx/html;
      index index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

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

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/choice.radio/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/choice.radio/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
}

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


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


    listen       80;
    server_name  my.domain;
    return 404; # managed by Certbot
}

尝试的修改及问题

我的WordPress安装在/var/www/html目录,尝试修改location /块为:

location / {
   root /var/www/html;
   index index.php;
}

但访问域名时PHP文件被直接下载而非解析,其他配置尝试均触发Nginx报错,请求帮助。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 04:35:00