【发布时间】:2019-01-22 22:51:26
【问题描述】:
我所有的路线都得到了404 Not Found。如果我访问 localhost/mylaravel,我可以打开 Laravel 页面,但如果我访问 localhost/mylaravel/login,我会得到 404 not found 页面。如果我在 /home 上更改回家路线并访问它,我得到 404 not found。
我正在使用 Laravel 框架 5.6.33
这是我的路线文件:
<?php
Route::get('/', function () {
return view('home/home');
});
Route::get('/login', function () {
return view('login/login');
});
这是我在 /etc/nginx/sites-available/default 的 nginx 配置
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
charset utf-8;
root /var/www/html/;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /mylaravel/ {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri $uri/ =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\. {
deny all;
}
location ~* ^.+\.(css|js|jpg|jpeg|gif|png|txt|ico|swf|xml|woff|woff2|ttf|mp3|svg|csv|xls|xlsx|eot|otf)$ {
access_log off;
expires modified +90d;
}
}
【问题讨论】:
-
谁在扔404? nginx还是laravel?考虑到 nginx 根目录应该指向
public/目录,就像这样:root /var/www/html/public/;if 您的应用程序目录恰好位于那里。最后,看起来您在同一个服务器块中配置了 2 个应用程序实例,您可以将其重构为 2 个不同的服务器块并避免很多麻烦。 -
@alariva nginx 抛出 404 not found page
-
指向 public 怎么样?可以发
ls -l /var/www/html/吗? -
我已经指向了public。有2个目录。 mylaravel 和 mylaravel-html
-
ls的输出呢,可以分享一下吗?