Laravel Windows 机器上 NGINX 中的路由运行不正常
Laravel Route in NGINX on Windows machine didn't work well
我只是在 windows 笔记本电脑上安装了我的 nginx 服务器。然后我像这样设置 nginx.conf 文件:
server {
listen 80;
server_name laravelninja.local;
root C:/blablabla/public;
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
运行 php-cgi 使用此语法 php-cgi.exe -b 127.0.0.1:9000
主持人也
127.0.0.1 laravelninja.local
在laravelninja.local/运行很好,但是当我去其他路线如laravelninja.local/pizzas时,这个错误来自nginx
2020/12/23 21:26:52 [error] 8980#11972: *7 CreateFile() "C:/blablabla/public/pizzas" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: laravelninja.local, request: "GET /pizzas HTTP/1.1", host: "laravelninja.local"
然后浏览器转到 google 并搜索 laravelninja。local/pizzas
这是我路线中的代码:
Route::get('/', function () {
return view('welcome');
});
Route::get('/pizzas', function () {
return view('pizzas');
});
和视图文件夹中 pizzas.blade.php 与 welcome.blade.php 相同级别的视图。
除了使用 laragon 之外,还有其他方法可以解决这个问题吗?
像这样在您的配置中添加这 2 个块:
server {
#
# your configs...
#
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ /\.ht {
deny all;
}
}
重新启动您的 NGINX 服务器。
(我不确定你的其他配置,但我相信第一个块就是你想要的。)
我只是在 windows 笔记本电脑上安装了我的 nginx 服务器。然后我像这样设置 nginx.conf 文件:
server {
listen 80;
server_name laravelninja.local;
root C:/blablabla/public;
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
运行 php-cgi 使用此语法 php-cgi.exe -b 127.0.0.1:9000
主持人也
127.0.0.1 laravelninja.local
在laravelninja.local/运行很好,但是当我去其他路线如laravelninja.local/pizzas时,这个错误来自nginx
2020/12/23 21:26:52 [error] 8980#11972: *7 CreateFile() "C:/blablabla/public/pizzas" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: laravelninja.local, request: "GET /pizzas HTTP/1.1", host: "laravelninja.local"
然后浏览器转到 google 并搜索 laravelninja。local/pizzas
这是我路线中的代码:
Route::get('/', function () {
return view('welcome');
});
Route::get('/pizzas', function () {
return view('pizzas');
});
和视图文件夹中 pizzas.blade.php 与 welcome.blade.php 相同级别的视图。
除了使用 laragon 之外,还有其他方法可以解决这个问题吗?
像这样在您的配置中添加这 2 个块:
server {
#
# your configs...
#
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ /\.ht {
deny all;
}
}
重新启动您的 NGINX 服务器。
(我不确定你的其他配置,但我相信第一个块就是你想要的。)