search
HomeBackend DevelopmentPHP Tutorialphp操控nginx解决方法

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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.