我正在尝试设置 Lumen - 建立在 Laravel 组件之上的“微框架”。服务器端有 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;
}
}
当我调用定义的路由时,这个配置工作正常,例如我看到“流明”。打开时的响应http://lumen.dev .但是当我尝试打开未定义的路由时 http://lumen.dev/404我在浏览器中看到“500 Internal Server Error”,在 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
。
关于redirect - Lumen + nginx = error 500, rewrite or internal redirection cycle while internally redirecting to "/index.php",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29645651/