【问题标题】:Laravel Route in NGINX on Windows machine didn't work wellWindows 机器上 NGINX 中的 Laravel Route 无法正常工作
【发布时间】:2020-12-23 15:03:49
【问题描述】:

我只是在我的 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"

然后浏览器去谷歌搜索 laravelninja.local/pizzas

这是我路线中的代码:

Route::get('/', function () {
     return view('welcome');
});

Route::get('/pizzas', function () {
     return view('pizzas');
});  

以及在views文件夹中与welcome.blade.php相同级别的pizzas.blade.php视图。

除了使用 laragon 之外,还有其他方法可以解决这个问题吗?

【问题讨论】:

  • 是的,欢迎页面工作正常,当我尝试访问其他路由时出现此错误。

标签: laravel windows nginx laragon


【解决方案1】:

像这样在你的配置中添加这两个块:

server {

    #
    # your configs...
    #

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ /\.ht {
        deny all;
    }
}

重启你的 NGINX 服务器。

(我不确定你的其他配置,但我相信第一个块就是你想要的。)

【讨论】:

  • 先生 100% 工作,非常感谢 :)
猜你喜欢
  • 2021-04-06
  • 2021-08-13
  • 2021-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-03
  • 2019-05-17
  • 1970-01-01
相关资源
最近更新 更多