search
HomeBackend DevelopmentPHP Tutorial php操控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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

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 Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.