duanluo9369
2016-02-08 20:48
采纳率: 100%
浏览 59
已采纳

Wordpress中的永久链接不能与Laravel + Nginx一起使用

I have a site developed with Laravel on my main route say www.example.com/. I have configured it properly with Nginx and php-fpm. My config is below.

Then I added a blog in route /blog (www.example.com/blog/) and configured it with Nginx alias.

Now the problem is that Permalinks in Wordpress are not working. Nginx redirects to Laravel's 404 page.

For example when user enters some URL like this: example.com/blog/about, Laravel's 404 page shows up which is weird.

How can I fix this? How can I config Nginx? What's Wrong?

server {
    listen       80;
    server_name  example.com;
    root /usr/share/nginx/html/;

    location /blog {
        try_files $uri $uri/ /index.php?$args;
        alias /usr/share/nginx/blog/;
        index  index.php index.html index.htm;

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME   /usr/share/nginx$fastcgi_script_name;
        }
    }

    location / {
        root   /usr/share/nginx/main_site;
        index  index.php index.html index.htm;

        try_files $uri $uri/ /index.php$is_args$args;

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}

图片转代码服务由CSDN问答提供 功能建议

我的主要路线上有一个用Laravel开发的网站,请说 www.example.com / 。 我已经使用Nginx和php-fpm正确配置了它。 我的配置如下。

然后我在路线 / blog www.example.com/blog / )中添加了一个博客, 使用Nginx alias 进行配置。

现在的问题是Wordpress中的永久链接无法正常工作。 Nginx重定向到Laravel的404页面。

例如,当用户输入这样的URL: example.com/blog/about 时,Laravel的404页面显示出来的是 很奇怪。

我该如何解决这个问题? 我该如何配置Nginx? 什么是错的?

  server {
 listen 80; 
 server_name example.com; 
 root / usr / share / nginx / html /; 
 
 location / 博客{
 try_files $ uri $ uri / /index.php?$args;
 alias / usr / share / nginx / blog /; 
 index index.php index.html index.htm; 
 
 location~  \ .php $ {
 fastcgi_pass 127.0.0.1:9000; 
 fastcgi_index index.php; 
包括fastcgi_params; 
 fastcgi_param SCRIPT_FILENAME / usr / share / nginx $ fastcgi_script_name; 
} 
} 
 
位置 / {
 root / usr / share / nginx / main_site; 
 index index.php index.html index.htm; 
 
 try_files $ uri $ uri / /index.php$is_args$args;
nn  location~ \ .php $ {
 fastcgi_pass 127.0.0.1:9000; 
 fastcgi_index index.php; 
 fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; 
 include fastcgi_params; 
} 
} 
} 
 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • ds122455 2016-02-08 21:12
    已采纳

    You do not need to use alias when the location matches the end of the alias path. See this document.

    The try_files in location /blog needs to default to the WordPress router (/blog/index.php) and not the Laravel router (/index.php).

    Try:

    location /blog {
        try_files $uri $uri/ /blog/index.php?$args;
        root /usr/share/nginx;
        ...
    
        location ~ \.php$ {
            ...
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        }
    }
    
    点赞 打赏 评论

相关推荐 更多相似问题