LNMP-php-fpm定义open_basedir
在php-fpm的pool池中,定义open_basedir限制用户访问文件的活动范围限制在指定的区域,通常是指站点的home目录路径。
1:编写conf文件
[root@host2 ~]# vim /usr/local/php-fpm/etc/php-fpm.d/test.conf
加入以下红色内容
[test]
listen = /tmp/test.sock
listen.mode=666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
request_slowlog_timeout = 1
slowlog = /usr/local/php-fpm/var/log/test-slow.log
php_admin_value[open_basedir]=/data/www/test_com:/tmp/
2:重新启动服务
[root@host2 ~]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
Nginx虚拟主机事先已经配置完成,不需要进行操作,配置如下
[root@host2 ~]# cat /usr/local/nginx/conf/vhosts/test.conf
server{
listen 80;
server_name www.test.com;
access_log /tmp/test.com-access.log;
error_log /tmp/test.com-error.log;
root /data/www/test_com;
location ~ \.php$ {
root html;
fastcgi_pass unix:/tmp/test.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www/test_com$fastcgi_script_name;
include fastcgi_params;
}
}
3:curl测试访问定义open_basedir站点中的文件
[root@host2 ~]# curl -x127.0.0.1:80 www.test.com/1.php
test php scripts.
配置成功显示文件输出信息,不成功显示No input file specified.
记录每一天有趣的事情!!

浙公网安备 33010602011771号