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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)