为php容器启用pathinfo
使用docker安装官方的php后,默认是没有启用pathinfo。如果要启用pathinfo,需要自己增加一个pathinfo的配置。
进入到nginx的容器的配置目录/etc/nginx(或是挂载到宿主主机的目录),新建一个名为pathinfo的文件,在这个文件中写入:
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
#try_files $fastcgi_script_name =404;
然后到网站的配置文件中,增加下面一行代码,引用pathinfo配置:
include pathinfo;
最终的代码是:
location ~ [^/]\.php(/|$){
root /var/www/html/website;
fastcgi_pass myphp:9000; #php的容器名为myphp,端口为9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/website$fastcgi_script_name;
include fastcgi_params;
include pathinfo; #启用pathinfo
}