亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    PHP Web 端如何操作 Nginx 配置

    PHP Web 端如何操作 Nginx 配置

    PHP Web端安全操作Nginx配置及熱重啟

    前言

    之前幫客戶整了一套基于GeoIP2的自動化AB站(Nginx Geoip2 處理不同國家 (或城市) 的訪問 ),客戶最近想通過管理端手動控制AB站切換
    PHP Web 端如何操作 Nginx 配置

    不建議使用system,exec等執(zhí)行shell命令的函數(shù)

    • 需要復(fù)雜的提權(quán)操作
    • 一般項目這些函數(shù)是被禁止
    • 作為一名合格的Phper除非特殊情況,否則是嚴(yán)禁在項目中啟用一些涉及到安全性的函數(shù)

    方案思路

    1. Nginx vhost配置文件中include片段配置
    2. 后端切換AB站時,PHP邏輯中修改第一步中引入片段配置
    3. Nginx Reload
      • 第一種方案:小型項目使用crontab定時執(zhí)行nginx -s reload(搭配worker_shutdown_timeout使用)
      • 第二種方案(推薦):修改后標(biāo)記需要reload狀態(tài)(File or DB or Cache),定時器通過python腳本查詢是否需要reload去執(zhí)行nginx -s reload

    方案一

    1.創(chuàng)建片段配置文件

    創(chuàng)建獨立片段Nginx配置文件,例如ar414.conf,然后在nginx vhostinclude

    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全局配置中設(shè)置worker_shutdown_timeout

    30s內(nèi)Nginx無法平滑退出,就強(qiáng)行關(guān)閉進(jìn)程

    nginx.conf

    ...worker_shutdown_timeout  30;

    5.定時執(zhí)行Nginx熱重啟

    crontab -e

    */5 * * * * nginx -s reload

    推薦教程:《PHP》

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號