【发布时间】:2016-06-23 16:37:03
【问题描述】:
最近我在 Nginx 中安装了 Laravel。 Laravel 应用程序主页工作正常,但路由页面出现 404 错误。
我的Nginx 配置如下:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.html index.htm index.php;
server_name localhost;
location / {
try_files $uri $uri/ /index.php?$query_string;
#try_files $uri $uri/ =404;
#try_files $uri $uri/ /index.php$is_args$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
当我访问像localhost/lar/public 这样的网址时,它工作正常。
声明了路由,但是当我访问像 localhost/lar/public/test 这样的 URL 时,它会出现 404 错误。
【问题讨论】:
-
您是否在
.env文件中正确配置了APP_URL? -
是的,我已经在 .env 文件中正确配置了 APP_URL。但还是不行
-
你应该将你的根设置为
root /home/user_name/Documents/laravel_project_name/public;