PHP Web端平安操作Nginx设置装备摆设及热重启
媒介
以前帮客户整了一套基于GeoIP2的主动化AB站(Nginx Geoip2 解决没有同国度 (或都会) 的拜访
),客户比来想经过治理端手动管制AB站切换
没有倡议应用system,exec等执行shell饬令的函数
- 需求复杂的提权操作
- 普通名目这些函数是被制止
- 作为一位及格的Phper除了非非凡状况,不然是严禁正在名目中启用一些触及到平安性的函数
计划思绪
- Nginx vhost设置装备摆设文件中
include
片断设置装备摆设 - 后端切换AB站时,PHP逻辑中修正第一步中引入片断设置装备摆设
- Nginx Reload
- 第一种计划:小型名目应用crontab按时执行nginx -s reload(搭配worker_shutdown_timeout应用)
- 第二种计划(保举):修正后标志需求reload状态(File or DB or Cache),按时器经过python剧本查问能否需求reload去执行nginx -s reload
计划一
1.创立片断设置装备摆设文件
创立自力片断Nginx设置装备摆设文件,例如ar414.conf
,而后正在nginx vhost
中include
ar414.conf
root /www/wwwroot/ahost;
2.站点设置装备摆设文件中include
设置装备摆设文件ar414.conf
site.conf
server { listen 80; server_name 0.0.0.0; index index.html; include /www/wwwroot/abhost/ar414.conf; }
3.后盾逻辑中操作ar414.conf
if($data['site_set'] == AbHostSiteEnum::Ahost) { //开启A站 $ahostPath = AbHostSiteEnum::AhostPath; file_put_contents('./ar414.conf',"root {$ahostPath};");}else { //开启B站 $bhostPath = AbHostSiteEnum::BhostPath; file_put_contents('./ar414.conf',"root {$bhostPath};");}
4.Nginx全局设置装备摆设中设置worker_shutdown_timeout
30s内Nginx无奈滑润圆滑加入,就强行封闭过程
nginx.conf
...worker_shutdown_timeout 30;
5.按时执行Nginx热重启
crontab -e
*/5 * * * * nginx -s reload
保举教程:《PHP》
以上就是PHP Web 端若何操作 Nginx 设置装备摆设的具体内容,更多请存眷资源魔其它相干文章!
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!