在lnmp环境下,laravel路由除了根目录,其他路由总是出现404页面。

这跟我们的nginx配置有关,是nginx的try_files $uri $uri/ =404;的问题,只需要将这句删除或注释掉就可以了。以下是nginx的配置,以供参考:

server {  
    listen 80;  

    server_name www.test.com;  

    root /data/www/laravel/public;  
    index index.html index.php index.htm;  

    location / {  
        #try_files $uri $uri/ =404;  
        try_files $uri $uri/ /index.php?$query_string;  
    }  
    location ~ \.php$ {  
        include snippets/fastcgi-php.conf;  
    #  
    #   # With php7.0-cgi alone:  
    #   fastcgi_pass 127.0.0.1:9000;  
    #   # With php7.0-fpm:  
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;  

    }  

}  

© 2017. All Rights Reserved.

博主的邮箱axaaxaa@163.com