【问题标题】:Nginx: hosting multiple WordPress sites as subdirectories returns 404 pagesNginx:将多个 WordPress 站点作为子目录托管返回 404 页
【发布时间】:2021-09-06 23:19:01
【问题描述】:

我有一个非 wordpress 根网站,它有 2 个子域(/blog 和 /shop)作为具有独立数据库的独立 wordpress 网站。我已经设法为他们设置了单独的 mysql 数据库,并且加载根页面(即 /blog 或 /shop)以及它们各自 wp-admins 中的任何页面也可以工作。

但是,加载不是根 /blog 或 /shop 页面的任何其他页面(例如 /blog/article1 或 /shop/product4)都会返回 404 错误页面。

为什么会发生这种情况,如何解决?

这是我在 /etc/nginx/sites-available 中的 .conf 文件(也符号链接到 /sites-enabled):

upstream wp-php-handler-four {
        server unix:/var/run/php/php7.4-fpm.sock;
}
server {
    listen 1224 default_server;
    listen [::]:1224 default_server;

    root /var/www/ecpn_sites;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;

    server_name _;

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

    location /blog {
        try_files $uri $uri/ /index.php?$args;
    }
    location /shop {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass wp-php-handler-four;
    }
}

我尝试将location ~ \.php$ 更改为location ~ /blog\.php$,在/blog 和/shop 块中添加index.php,并将?$args 更改为?q=$uri&$args,但无济于事。

如果我是 Nginx 新手,我将不胜感激。谢谢。

【问题讨论】:

  • try_files 语句的最后一个参数应该是/blog/index.php?$args/shop/index.php?$args
  • 谢谢 - 成功了

标签: wordpress nginx


【解决方案1】:

try_files 更改为:

location /blog {
    try_files $uri $uri/ /blog/index.php?$args /blog/index.php?$uri&$args ;
}

location /shop {
    try_files $uri $uri/ /shop/index.php?$args /shop/index.php?$uri&$args ;
}

【讨论】:

    猜你喜欢
    • 2023-04-06
    • 2017-02-03
    • 2018-11-23
    • 2019-07-13
    • 2015-05-21
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多