You need to enable JavaScript to run this app. Windows环境下Nginx部署Laravel项目出现404及No input file specified错误
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下Nginx部署Laravel项目出现404及No input file specified错误

问题排查与解决步骤

1. 修正访问地址

你当前Nginx配置的root已经直接指向Laravel项目的public目录:C:/Projects/TestProject/public,因此不需要在访问路径中额外拼接项目目录,拼接后Nginx会尝试在C:/Projects/TestProject/public/TestProject/public路径下查找文件,自然会触发404错误。

  • 正确的Laravel首页访问地址为:http://localhost
  • 测试文件的正确访问地址为:http://localhost/Test.php

2. 修正Nginx配置的参数顺序

你当前的PHP location块中,include fastcgi_params 放在了自定义fastcgi_param的后面,fastcgi_params内置的同名参数会覆盖你手动定义的SCRIPT_FILENAME参数,这也是导致No input file specified的常见原因。修改后配置如下:

server {
    listen       80;
    server_name  localhost;
    root         C:/Projects/TestProject/public;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9999;
        fastcgi_index  index.php;
        include        fastcgi_params; # 先引入默认配置
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; # 再覆盖自定义参数
    }
}

修改配置后重启Nginx生效。

3. 验证PHP CGI服务配置

确认你启动的PHP-CGI服务监听的端口确实是9999,你可以通过Windows cmd执行以下命令查看端口占用:

netstat -ano | findstr "9999"

如果端口不匹配,可以在PHP安装目录下启动CGI服务时指定对应端口:

C:\PHP\php-cgi.exe -b 127.0.0.1:9999

4. 配置Laravel目录权限(Windows环境)

给Laravel项目下的storage和bootstrap/cache目录添加Everyone读写权限,避免Laravel运行时写入缓存报错。

内容的提问来源于stack exchange,提问作者David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.21 18:45:03