PHPweb端安全操作Nginx配置及热重启前言ar414帮助客户搭建基于GeoIP2的自动化AB站(【NginxGeoip2处理不同国家(或城市)访问】(https://learnku.com/articles/...),客户最近想通过管理端手动控制AB站切换,不建议使用system、exec等函数执行shell命令,需要复杂的提权操作,一般禁止使用这些函数,如一个合格的Phper,除非有特殊情况,否则严禁在项目中启用一些安全相关的功能###解决思路Nginxvhost配置文件包含片段配置后端切换AB站,修改第一步中的PHP逻辑为先介绍片段配置NginxReload第一种方案:小项目使用crontab定时执行nginx-sreload(配合worker_sh使用utdown_timeout)。方案二(推荐):修改后标记需要重新加载(File或DB或Cache),timer使用python脚本查询是否需要重新加载。执行nginx-sreload解决方法一1.创建分片配置文件创建一个独立的分片Nginx配置文件,比如ar414.conf,然后在nginxvhost中includear414.confroot/www/wwwroot/ahost;2.在站点配置文件中包含配置文件ar414.confsite.confserver{listen80;服务器名称0.0.0.0;索引index.html;包括/www/wwwroot/abhost/ar414.conf;}3.运行ar414.confif($data['site_set']==inbackgroundlogicAbHostSiteEnum::Ahost){//打开站点A$ahostPath=AbHostSiteEnum::AhostPath;file_put_contents('./ar414.conf',"root{$ahostPath};");}else{//打开B站$bhostPath=AbHostSite枚举::主机路径;file_put_contents('./ar414.conf',"root{$bhostPath};");}4.在Nginx全局配置中,设置worker_shutdown_timeout在30s以内,Nginx无法顺利退出,所以强行关闭nginx.conf进程。.worker_shutdown_timeout30;5.定时Nginx热重启crontab-e*/5****nginx-sreload
