我正在尝试设置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选项必须指向公共目录:
server {
server_name lumen.dev;
root /var/www/lumen/public;
出现错误是因为它试图调用相对于根目录的/index.PHP?$query_string.因此,它试图在无尽的循环中查找/var/www/lumen/index.PHP.