php - `wp-admin` 使用 NGINX 从不同文件夹提供 Laravel 和 WordPress 时无法正常工作

标签 php laravel wordpress ubuntu nginx

我正在使用以下 NGINX 配置来提供 Laravel 应用程序和 WordPress 博客。该博客曾经位于子域 ( blog.example.com ),但现在移动到 example.com/blog .
我试图将 Laravel 应用程序(/var/www/vhosts/example.com/httpdocs/laravel/public)和 WordPress(/var/www/vhosts/example.com/httpdocs/wordpress/)安装到不同的文件夹中,以便于管理。 Laravel 路由按预期工作,但 WordPress example.com/blog/wp-admin路线不工作。下面是我的 NGINX 配置。

server {
    listen 80;
    server_name example.com;
    rewrite ^/(.*) https://example.com/$1 permanent;
}

server {
    listen 443 ssl;
    server_name example.com;

    charset utf-8;

    ssl    on;
    ssl_certificate     /etc/ssl/example.crt;
    ssl_certificate_key /etc/ssl/example.key;

    root /var/www/vhosts/example.com/httpdocs/laravel/public;
    index index.html index.htm index.php;

    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; }

    error_page 403 /index.php;
    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.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_read_timeout 180;
        include fastcgi_params;
    }

    ## Wordpress blog configuration
    location ^~ /blog/ {
        alias  /var/www/vhosts/example.com/httpdocs/wordpress/;

         if (!-e $request_filename) {
            rewrite ^ /blog/index.php last;
        }

        try_files $uri $uri/ /blog/index.php;

        location ~ \.php$ {
            fastcgi_split_path_info ^(/blog)(/.*)$;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_read_timeout 180;
            include fastcgi_params;
         }
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
请您指出我为什么无法访问wp-admin ?有一个更好的方法吗?谢谢

最佳答案

尝试这样做。为/blog/设置“根”并从重写中删除/blog/。
并删除根目录/xyz/wordpress 末尾的斜杠;

 root /var/www/vhosts/example.com/httpdocs/wordpress;
 
 rewrite .* /index.php last;
 
 try_files $uri $uri/ /index.php;

关于php - `wp-admin` 使用 NGINX 从不同文件夹提供 Laravel 和 WordPress 时无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72524092/

相关文章:

php - WP 字幕 - 格式

php - 按键获取数组值时出错

laravel - 集合到具有特定键的关联数组 [L5.2]

php - Laravel 扩展供应商类

php - 我在哪里放置事件监听器和处理程序?

wordpress - Woocommerce 操作钩子(Hook)在订阅续订时执行功能

php - 更改 WordPress SQL 数据库以自定义帖子类型

php - 如何在PHP中几秒钟后禁用电子邮件确认链接

php - Sql 运算符 "and"和 "or"无法正常工作

php - 转换mysql unix时间并使用BETWEEN