IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

PHP Web 端操作 Nginx 配置

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

PHP Web端安全操作Nginx配置及热重启

前言

之前帮客户整了一套基于GeoIP2的自动化AB站(Nginx Geoip2 处理不同国家 (或城市) 的访问 ),客户最近想通过管理端手动控制AB站切换

120_1.png

不建议使用system,exec等执行shell命令的函数

  • 需要复杂的提权操作
  • 一般项目这些函数是被禁止
  • 作为一名合格的Phper除非特殊情况,否则是严禁在项目中启用一些涉及到安全性的函数

方案思路

1、 Nginx vhost配置文件中include片段配置
2、 后端切换AB站时,PHP逻辑中修改第一步中引入片段配置
3、 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 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全局配置中设置worker_shutdown_timeout

30s内Nginx无法平滑退出,就强行关闭进程

nginx.conf

...
worker_shutdown_timeout  30;

5.定时执行Nginx热重启

crontab -e

*/5 * * * * nginx -s reload

文章永久链接:https://tech.souyunku.com/?p=33474


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(89) 打赏



未经允许不得转载:搜云库技术团队 » PHP Web 端操作 Nginx 配置

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367