通过PHP脚本重新启动Nginx [英] Restart Nginx through a PHP Script

查看:117
本文介绍了通过PHP脚本重新启动Nginx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在努力使我的WordPress插件与nginx兼容.此插件需要访问wp-content/uploads目录中的.conf文件,以便可以添加必需的规则.当前,它会更新同一目录中的.htaccess文件,并且更改无需更改即可立即生效.因为nginx需要service nginx reload才能使配置更改生效,所以我正在寻找一种在脚本中执行此操作的方法.我不确定甚至exec()都可以做到这一点,因为service nginx reload必须以root用户或使用sudo来运行.我在StackExchange,Google以及我所知道的其他地方进行了广泛的搜索,甚至找不到起点.

I'm currently working to make a WordPress plugin of mine compatible with nginx. This plugin requires access to a .conf file in the wp-content/uploads directory, so that it can add in the required rules. Currently, it updates an .htaccess file in the same directory, and the changes take effect immediately without intervention. Because nginx requires service nginx reload to allow configuration changes to take effect, I am looking for a way to do that in my script. I'm not sure that even exec() would work for this, as service nginx reload is required to be run as root or using sudo. I've searched far and wide on StackExchange, Google, and everywhere else that I know of, and I can't even find a starting place.

推荐答案

出于安全考虑,给运行Web服务器的用户sudo/root访问权限是一件非常不好的事情.相反,您可以使用一个信号量文件,并由root运行一个cron作业,该作业每5分钟运行一次(如果需要,则以更高的频率运行),以查找该文件的存在.如果存在,它将发出service nginx reload命令并删除文件.

Security wise, it would be a VERY bad thing to give the user that runs the web server sudo/root access. Rather, you could use a semaphore file and have a cron job run by root that runs every 5 minutes (or higher frequency if required) that looks for the presence of this file. If present, it issues the service nginx reload command and deletes the file.

这篇关于通过PHP脚本重新启动Nginx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆