Nginx 将根位置更改为 wordpress 站点

Nginx 将根位置更改为 wordpress 站点

目前我在 下有一个 Wordpress 网站/var/www/html/wordpress,在 下还有其他 php 项目/var/www/html/projects。我希望我的根位置指向 wordpress。这是我当前的 nginx 配置:

server {
    listen       80 default_server;
    server_name  _;
    set $yii_bootstrap "index.php";
    root         /var/www/html;
    client_max_body_size 2M;
    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;
    location /projects/inspection/ {
        root /var/www/html;
            try_files $uri /index.php$is_args$args;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
            fastcgi_index index.php;
            fastcgi_pass 127.0.0.1:9000;    
        }

    location /projects/ {
            root  /var/www/html;
            index  index.html $yii_bootstrap;
            try_files $uri $uri/ /$yii_bootstrap?$args /index.php$is_args$args;
        }
    location / {
        root  /var/www/html/wordpress;
        try_files $uri $uri/ =404;
        index index.php index.html index.htm;
    }       
    location ~ \.php{
          fastcgi_split_path_info ^(.+\.php)(/.+)$;
          # fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
          fastcgi_pass php-fpm;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param SCRIPT_NAME $fastcgi_script_name;
          include fastcgi_params;
      }


        error_page 404 /404.html;
            location = /40x.html {
        }

    }

但是它返回 404。我尝试改为输入alias,它返回 403 forbidden。我该如何处理?

答案1

你没有说出究竟是什么返回了 404。然而,一个可能的原因是你的 WordPress 缺少前端控制器模式配置,也就是说,你location的 WordPress 应该有这个:

location / {
    root /var/www/html/wordpress;
    try_files $uri $uri/ /index.php;
}

相关内容