centos7上的h5ai折腾记

过程:
安装php-fpm和nginx,且经验证二者在其他项目可以正常使用。
从debian8拷贝过来_h5ai的nginx配置如下:

     location ~ [^/].php(/|$) {
         fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; #反注释
         include /etc/nginx/snippets/fastcgi-php.conf;
     }

由于centos7服务器上没有/etc/nginx/snippets/fastcgi-php.conf这个文件,所以把这行改成了include fastcgi_params;,即:

# _h5ai file server
server {
	listen  12345;
        # server_name _;
	root /home/chudongyu/rtorrent/download;
        index  index.html  index.php  /_h5ai/public/index.php;

	location / {
		try_files $uri $uri/ /index.php$is_args$args;
	}

    location ~ [^/].php(/|$) {
        fastcgi_pass   127.0.0.1:9000;
        include        fastcgi_params;
    }
}

但是_h5ai并不能用,症状:
打开172.19.240.132:12345,只有空白页面,不显示任何东西。检查nginx的日志里面完全正常,没有错误。
在文件夹下建立index.html,发现可以显示,但是建立index.php()还是一批空白,啥都没有。
折腾良久,最终发现仅仅include fastcgi_params'是不够的,还要添加:

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

完整的正确配置如下

# _h5ai file server
server {
	listen  12345;
        # server_name _;
	root /home/chudongyu/rtorrent/download;
        index  index.html  index.php  /_h5ai/public/index.php;

	location / {
		try_files $uri $uri/ /index.php$is_args$args;
	}

    # location ~ [^/].php(/|$) {
    #     fastcgi_pass   127.0.0.1:9000;
    #     include        fastcgi_params;
    # }

    location ~ .php$ {
            root           /home/chudongyu/rtorrent/download;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}

参考:https://blog.csdn.net/zsx0728/article/details/81183056

一个视频播放器更好用的_h5ai修改版:
【自用分享】 h5ai HTML5播放器(DPlayer)版
https://www.hostloc.com/thread-438265-1-2.html
直接下载地址: https://www.moerats.com/usr/down/h5ai_dplayer+modified+by+icycat.zip

另一种配置(在其他端口使用/download/路径,如xxx:8080/download/):

.......
    location ~ /download(/|$) {
        root           /home/chudongyu/rtorrent;
        index  index.html  index.php  /download/_h5ai/public/index.php;
		try_files $uri $uri/ /index.php$is_args$args;

        #  #NOT WORK:
        #  root           /home/chudongyu/rtorrent/download;
        #  index  index.html  index.php  /_h5ai/public/index.php;
		#  try_files $document_root $document_root/ /index.php$is_args$args;  # $real_script为空的时候,还是回访问download/download...
        #  # try_files index.html /_h5ai/public/index.php;
        #  # fastcgi_pass   127.0.0.1:9000;
        #  # fastcgi_index /_h5ai/public/index.php;
        #  # fastcgi_param  SCRIPT_FILENAME  $document_root;
        #  # include        fastcgi_params;
    }
    location ~ /download/.php$ {
        root           /home/chudongyu/rtorrent/download;
        index  index.html  index.php  /_h5ai/public/index.php;
        # return 200 '$fastcgi_script_name';  # 返回的是 /download/...
        set $real_script '';
        if ( $fastcgi_script_name ~ /download(.*) ){  # 根据location的匹配规则,$1不会为空
            set $real_script $1;
        }
        # return 200 $real_script;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$real_script;
        include        fastcgi_params;
    }
.......
}

在云服务器搭了个下载器从紫荆下电影。。。

原文地址:https://www.cnblogs.com/dylanchu/p/10231256.html