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;
        }
    }
}
  • 写回答

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;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?