Laravel路由不生效,404,除了/ 都不行,关于nginx环境下laravel除了默认路由都出现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

 

 

 

复制代码
server {
        listen        80;
        server_name  yh.lardemo.com;
        root   "C:/Users/Administrator/Desktop/laravel_demo1/laravel_demo";
        location / {
            index index.php index.html error/index.html;
            try_files $uri $uri/ /public/index.php$is_args$query_string;
            error_page 400 /error/400.html;
            error_page 403 /error/403.html;
            error_page 404 /error/404.html;
            error_page 500 /error/500.html;
            error_page 501 /error/501.html;
            error_page 502 /error/502.html;
            error_page 503 /error/503.html;
            error_page 504 /error/504.html;
            error_page 505 /error/505.html;
            error_page 506 /error/506.html;
            error_page 507 /error/507.html;
            error_page 509 /error/509.html;
            error_page 510 /error/510.html;
            include C:/Users/Administrator/Desktop/laravel_demo1/laravel_demo/nginx.htaccess;
            autoindex  off;

        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}
复制代码

转载:https://blog.csdn.net/qq_37131747/article/details/123420841

posted @   搬砖小伙子  阅读(647)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示