在 Laravel 7 框架上的 public/blog 中安装 WordPress

Installing WordPress inside public/blog on Laravel 7 framework

我正在尝试在我的 Laravel 7 应用程序的 public/blog 目录中安装 WordPress 博客,以便可以通过 example.com/blog URL.

我 运行宁 Ubuntu 20.04 PHP7.4 和 NGINX 使用 Laravel Forge.

这是我 nginx.conf 中的内容:

location /blog/ {
    try_files $uri $uri/ @wordpress;
    }
    
    location @wordpress {
        rewrite /blog/ /blog/index.php;
    }
    
    location ^/blog/index.php(/.*)?$ {
        fastcgi_split_path_info ^(/blog/index.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        include fastcgi_params;
    }
location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/www.example.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        try_files /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php?$query_string;
        include fastcgi_params;
    }

我遇到的问题是当我尝试访问博客时,第一次 运行 安装 WordPress,我被重定向到以下 URL https://www.example.com/blog/wp-admin/install 但是我有一个找不到文件的异常,因为框架正在尝试在 /home/forge/www.example.com/storage/app/protected/files/blog/wp-admin/install 中寻找 install.php,这显然不存在。

问题是为什么会发生这种情况,为什么即使在将 NGINX 和 php7.4-fpm 设置到博客的正确位置后框架仍然这样做?

我已经尝试关闭我所有的客户端路由来测试它,但到目前为止什么都没有。

首先非常感谢Skyro682推荐解决方案

如果您遇到与我相同的情况,请执行以下操作。

在您的常规位置块上方添加以下内容 nginx.conf:

    location ^/blog {
        index index.php;
        try_files $uri $uri/ /blog/index.php$is_args$args;

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }
    }
    
#This is is your regular location for Laravel 
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

从 Laravel Forge 面板或终端重新启动您的 NGINX 和 PHP7.4。

您应该看不到 WordPress 的安装屏幕。

这种方法适用于 SEO 友好的 URL