将博客从子域移动到/blog

问题描述 投票:0回答:1

我的服务器应用程序使用 Laravel,直到最近我还在

blog.server.com

托管了一个 WordPress 博客

我想将其更改为

server.com/blog

我通过添加以下内容更新了主 nginx 配置:

location ^~ /blog {
    root /home/ploi/blog.server.com/public;
    index index.php index.html index.htm;
    try_files $uri $uri/ /blog/index.php?$query_string;

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_buffers 16 16k;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
 }

这种作品。它加载新的 /blog url 和帖子,但是:

  • 没有加载静态资源 (
    js, png, css, etc
    )
  • server.com/blog/wp-admin/
    无限循环

我该如何解决这个问题?

php laravel nginx
1个回答
1
投票

你可以试试这个,对我有用:

    location /blog {
        alias /home/ploi/blog.server.com/public;
        
        try_files $uri $uri/ @blogrewrite;

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }   
    }

    location @blogrewrite {
        rewrite /blog/(.*)$ /blog/index.php?/$1 last;
    }

我使用了“命名位置”(@blogrewrite),但坦率地说,我不知道为什么这是必要的,但它避免了递归。

© www.soinside.com 2019 - 2024. All rights reserved.