基于 LNMP 2.1 部署后,接口响应 500 ,原因在于 .user.ini 的配置 open_basedir 有误
1、接口响应 500。如图1
2、查看 Nginx 的 error log。报错:PHP message: PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/qdx/src/vendor/autoload.php) is not within the allowed path(s):如图2
1 | 2025/03/11 10:46:31 [error] 323148#0: *3 FastCGI sent in stderr: "PHP message: PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/qdx/src/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/qdx/src/api/web/:/tmp/:/proc/) in /home/wwwroot/qdx/src/api/web/index.php on line 6PHP message: PHP Warning: require(/home/wwwroot/qdx/src/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/qdx/src/api/web/index.php on line 6PHP message: PHP Fatal error: require(): Failed opening required '/home/wwwroot/qdx/src/api/web/../../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/qdx/src/api/web/index.php on line 6" while reading response header from upstream, client: 101.204.100.38, server: qdxapi.ikhw.cn, request: "POST /unregistered-user/get-id HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "qdxapi.ikhw.cn" |
3、参考:LNMP添加、删除虚拟主机及伪静态使用教程 防跨目录设置 查看 .user.ini 中的内容
1 2 | [root@iZ2zeaj7tnbv8d3gsoy1w5Z qdx]# cat .user.ini open_basedir=/home/wwwroot/qdx:/tmp/:/proc/ |
4、编辑 .user.ini。.user.ini文件无法直接修改,如要修或删除需要先执行:chattr -i /home/wwwroot/qdx/.user.ini
1 2 | [root@iZ2zeaj7tnbv8d3gsoy1w5Z qdx]# cat .user.ini open_basedir=/home/wwwroot/qdx/src:/tmp/:/proc/ |
5、仍然报错。最终决定删除掉 .user.ini。参考:LNMP下防跨站、跨目录安全设置,仅支持PHP 5.3.3以上版本 直接在 php.ini 中编辑
1 | 2025/03/11 10:53:59 [error] 323149#0: *5 FastCGI sent in stderr: "PHP message: PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/qdx/src/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/qdx/src/api/web/:/tmp/:/proc/) in /home/wwwroot/qdx/src/api/web/index.php on line 6PHP message: PHP Warning: require(/home/wwwroot/qdx/src/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/qdx/src/api/web/index.php on line 6PHP message: PHP Fatal error: require(): Failed opening required '/home/wwwroot/qdx/src/api/web/../../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/qdx/src/api/web/index.php on line 6" while reading response header from upstream, client: 101.204.100.38, server: qdxapi.ikhw.cn, request: "POST /unregistered-user/get-id HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "qdxapi.ikhw.cn" |
1 | 2025/03/11 10:53:59 [error] 323149#0: *5 FastCGI sent in stderr: "PHP message: PHP Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/qdx/src/vendor/autoload.php) is not within the allowed path(s): (/home/wwwroot/qdx/src/api/web/:/tmp/:/proc/) in /home/wwwroot/qdx/src/api/web/index.php on line 6PHP message: PHP Warning: require(/home/wwwroot/qdx/src/vendor/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/qdx/src/api/web/index.php on line 6PHP message: PHP Fatal error: require(): Failed opening required '/home/wwwroot/qdx/src/api/web/../../vendor/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/qdx/src/api/web/index.php on line 6" while reading response header from upstream, client: 101.204.100.38, server: qdxapi.ikhw.cn, request: "POST /unregistered-user/get-id HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "qdxapi.ikhw.cn" |
近期评论