Lumen + nginx = error 500,重写或内部重定向循环同时内部重定向到“/index.php”

Lumen + nginx = error 500, rewrite or internal redirection cycle while internally redirecting to "/index.php"

我正在尝试在 Laravel 的组件之上构建 Lumen - "micro-framework"。在服务器端有 nginx + php-fpm.

这是我的 nginx 配置:

server {
    server_name lumen.dev;
    root /var/www/lumen;

    location / {
        include         /etc/nginx/fastcgi_params;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_NAME      /index.php;
        fastcgi_param   SCRIPT_FILENAME  /var/www/lumen/public/index.php;

        try_files $uri $uri/ /index.php?$query_string;
    }
}

当我调用定义的路由时,这个配置工作正常,例如打开时我看到 "Lumen." 响应 http://lumen.dev. But when I try to open undefined route like http://lumen.dev/404 我在浏览器中看到“500 内部服务器错误”,在 nginx 错误日志中看到这条消息:

rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 127.0.0.1, server: lumen.dev

如何修复我的 nginx conf 以使其正常工作?

root 选项必须指向 public 目录:

server {
    server_name lumen.dev;
    root /var/www/lumen/public;

错误出现是因为它试图调用相对于根目录的/index.php?$query_string。所以它试图在无限循环中找到 /var/www/lumen/index.php