其實出現這個問題只會出現在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