Home Backend Development PHP Tutorial php操控nginx解决方法

php操控nginx解决方法

Jun 13, 2016 pm 01:21 PM
kill nginx php process root

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 of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 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: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 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 Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 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.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

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

See all articles