我正在为内容管理系统创建基于Web的phar安装程序。问题出在nginx服务器上,即使最简单的phar文件也会导致nginx中的重定向。阿帕奇的一切都很好。
我对nginx的经验很少,所以我无法弄清楚这一点。寻找所有,以及我能得到的任何帮助。提前谢谢。
来源:
这是.phar 的构建脚本(我将.phar重命名为.php,因此不需要任何时髦的.htaccess规则)
<?php
// create with alias "project.phar"
$phar = new Phar('test.phar', 0, 'test.phar');
$phar->buildFromDirectory('./files');
$phar->setStub($phar->createDefaultStub('cli.php', 'index.php'));
@rename('test.phar','test.php');
?>
这是简单的index.php文件
<?php
echo "This does not work in nginx\n";
?>
这是nginx配置:
server {
listen 0.0.0.0:80;
root /var/www/;
index index.html index.php;
include /etc/nginx/include/php;
location /test2 {
autoindex on;
}
}
和/ etc / nginx / include / php文件
include /etc/nginx/fastcgi_params;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $fastcgi_path_info;
try_files $fastcgi_script_name =404;
fastcgi_pass unix:/var/run/nginx/php-fastcgi.sock;
fastcgi_index index.php;
include fastcgi_params;
}
和fastcgi_params文件
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
修改
这个问题与fastcgi模式有关,因为我使用相同的处理程序在apache中重现了它。 默认存根导致重定向循环,要求我使用固定存根。我将发布另一个问题
答案 0 :(得分:0)
我自己看过这样的重定向循环并报告错误 - https://bugs.php.net/bug.php?id=67587
现在已经在PHP中修复了该错误; PHP 5.6.0,5.5.15和5.4.31。