Home  >  Article  >  Backend Development  >  php操控nginx解决方法

php操控nginx解决方法

WBOY
WBOYOriginal
2016-06-13 10:34:49993browse

php操控nginx
问个问题了...

现有nginx.php脚本来操控nginx。
如有启动、停止、重启、等。

php与nginx都不是root权限。
用exec system函数,
基本的一些 ls cp 命令是没问题。

kill -INT `cat /usr/local/nginx/logs/nginx.pid`;
怎么测试都执行不了。
cat /usr/local/nginx/logs/nginx.pid是没问题,就是kill命令执行不了,
估计kill权限问题,不知要怎么搞。


还有假设能把nginx停止了。那nginx.php自己都不能运行了,是得上服务器来启动nginx了。
要保证nginx.php能正常运行,这个要怎么处理好些? 

是要新开端口、进程什么的么?
有这方面经验的朋友指点下啊。
或大牛们给些资料来学习学习。




------解决方案--------------------
http://www.osseye.com/?p=295
找来的文章 希望有所帮助
------解决方案--------------------
又是权限问题,值得关注,坐等求解~~
------解决方案--------------------
chmod 755 试试
------解决方案--------------------
写个shell 然后用php 来调用这个shell 可行?

我擦 bb机...想当年哥1500的中文 润讯bb机别在裤带上多耀眼...
------解决方案--------------------
当然不能通过web接口操作了- -。。

写个php脚本,使用ssh操作远程服务器执行nginx重启关闭等,相关接口:
http://cn.php.net/ssh2,服务器sshd服务打开。

这样的话,权限将与你的ssh user相关,用适当的用户ssh执行command即可。

SYNOPSIS
#include

int kill(pid_t pid, int sig);

For a process to have permission to send a signal to a process designated by pid, unless the sending process has appropriate privileges, the real or
effective user ID of the sending process shall match the real or saved set-user-ID of the receiving process.

这是Kill的权限问题,要么你是root,要么你和nginx进程的真实用户ID一样,要么和nginx进程的保存设置用户ID一样,你应该都可以实现。

------解决方案--------------------
从Nginx的C源码实现角度,master进程是root启动的,它的实际用户ID是文件属主,如果master bind 80后setuid切到其他有效用户ID,那么savfed set-user-ID将是root。

所以你如果想kill nginx,你要么以root身份ssh,要么是Nginx这个二进制文件的属主身份ssh,这两者都可以实现kill。

其他的都没戏,别看你nginx的配置文件里写的工作用户和工作组,都是没权利的,它们是nginx的worker进程setuid降低权限使用的。
------解决方案--------------------

探讨

这个ssh2也有了解过点点,这个是要远程登录吧?要root的密码。。
我是写给别人用的要别人提供root密码好像有些不太妥啊。

引用:

当然不能通过web接口操作了- -。。

写个php脚本,使用ssh操作远程服务器执行nginx重启关闭等,相关接口:
http://cn.php.net/ssh2,服务器sshd服务打开。

这样的话,权限将与你的ss……

------解决方案--------------------
探讨

-rwxr-xr-x 1 root root 3874792 Jul 5 11:55 /usr/local/nginx/sbin/nginx

还有你能说下#1楼提到的方法吗?



引用:

引用:

这个ssh2也有了解过点点,这个是要远程登录吧?要root的密码。。
我是写给别人用的要别人提供root密码好像有些不太妥啊。
……

------解决方案--------------------
不知道你遇到了什么问题?
nginx 与其他提供持续服务的软件一样,都需要由管理员级别用户启动,否则一旦用户注销了,服务也就停止了

你说用 nginx.php 脚本来操控 nginx
从 nginx.php 文件名上看,应该是以 web 方式运行的
但 nginx 一旦停止,nginx.php 如何运行?

如果是通过 shell,那有何必多此一举

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php怎么格式化字符串Next article:PHP如何调试?