其实出现这个问题只会出现在laravel被部署在二级目录中,其原因是,除了请求根目录/ (http://www.xxx.com/public/),会请求public/index.php

 

你在浏览器输入其他路由地址时,会把你的请求定位到:http://www.xxx.com/index.php 里面,自然都是404了

 

官网也有解决办法:

https://laravel.com/docs/5.0/installation#pretty-urls

打开nginx的配置文件,在location中添加上try_files $uri $uri/ /index.php?$query_string; 这样laravel在route中的路由就可以正常访问了

 

如果照搬那应该死的很惨:把上面的配置改为下面的 就可以正常访问了

    location / {
        root   /var/nginx/html/123.com;
        index  index.html index.htm index.php;
      try_files $uri $uri/ /public/index.php$is_args$query_string;
    }

 

重点是让请求定位到:public的目录下...

 

参考: https://www.jianshu.com/p/f5096c6d8ca2

 https://segmentfault.com/q/1010000002422408

 

相关文章:

  • 2021-08-24
  • 2021-06-23
  • 2021-12-30
  • 2022-12-23
  • 2021-07-10
  • 2021-06-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-18
  • 2021-05-21
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
相关资源
相似解决方案