python - 以apache(python app)作为独立进程启动nginx

标签 python apache nginx crash subprocess

我正在通过在Debian 10系统中的apache上运行的自定义Web应用程序(python)管理Nginx。
它工作正常,我可以重新启动,重新加载,停止,检查nginx的语法而不会出现问题。
当通过自定义Web应用程序(apache)启动Nginx时出现问题,然后如果我通过“service apache2 restart”或“/etc/init.d/apache2 restart”重新启动/停止a​​pache,Nginx也将停止。
我启动nginx的方式是使用python子进程:subprocess.Popen(['sudo', '/opt/waf/nginx/sbin/nginx'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)这可行,但是如果我手动重新启动/停止a​​pache,nginx服务也将停止。
我尝试将nginx.conf从“用户www-data”更改为“用户根”,以查看是否可以解决更改用户的问题,但是没有,问题仍然存在。
在nginx.conf中使用ps aux --forest和“user www-data”进行检查

root       2637  0.0  0.2  20312  7984 ?        Ss   15:20   0:00 /usr/sbin/apache2 -k start
www-data   2638  2.4  1.9 461320 59732 ?        Sl   15:20   0:09  \_ /usr/sbin/apache2 -k start
www-data   2639  0.0  0.9 2014312 28572 ?       Sl   15:20   0:00  \_ /usr/sbin/apache2 -k start
www-data   2640  0.0  0.9 2014328 28528 ?       Sl   15:20   0:00  \_ /usr/sbin/apache2 -k start
root       3322  0.0  1.9 190476 59156 ?        Ss   15:27   0:00 nginx: master process /opt/waf/nginx/sbin/nginx
www-data   3323  0.0  2.8 212248 85172 ?        S    15:27   0:00  \_ nginx: worker process
www-data   3324  0.0  2.8 212248 85232 ?        S    15:27   0:00  \_ nginx: worker process
www-data   3325  0.0  2.8 212248 85172 ?        S    15:27   0:00  \_ nginx: worker process
www-data   3326  0.5  2.8 212248 85172 ?        S    15:27   0:00  \_ nginx: worker process
www-data   3327  0.0  2.1 190556 64440 ?        S    15:27   0:00  \_ nginx: cache manager process
www-data   3328  0.0  2.1 190556 64440 ?        S    15:27   0:00  \_ nginx: cache loader process
在nginx.conf中使用带有“用户根”的ps aux --forest检查
root       2637  0.0  0.2  20312  7984 ?        Ss   15:20   0:00 /usr/sbin/apache2 -k start
www-data   2638  5.2  1.5 455400 47264 ?        Sl   15:20   0:01  \_ /usr/sbin/apache2 -k start
www-data   2639  0.2  0.8 2014236 24608 ?       Sl   15:20   0:00  \_ /usr/sbin/apache2 -k start
www-data   2640  0.1  0.7 2014328 23160 ?       Sl   15:20   0:00  \_ /usr/sbin/apache2 -k start
root       2758  0.0  1.9 190476 59156 ?        Ss   15:20   0:00 nginx: master process /opt/waf/nginx/sbin/nginx
root       2759  0.0  2.8 212248 85232 ?        S    15:20   0:00  \_ nginx: worker process
root       2760  0.0  2.8 212248 85232 ?        S    15:20   0:00  \_ nginx: worker process
root       2761  0.0  2.8 212248 85232 ?        S    15:20   0:00  \_ nginx: worker process
root       2762  0.0  2.8 212248 85232 ?        S    15:20   0:00  \_ nginx: worker process
root       2763  0.0  2.1 190556 64352 ?        S    15:20   0:00  \_ nginx: cache manager process
root       2764  0.0  2.1 190556 64352 ?        S    15:20   0:00  \_ nginx: cache loader process
我不知道如何解决此问题,我需要由Web应用程序启动的Nginx作为完全独立的过程。
任何帮助都非常感谢。
干杯。

最佳答案

我想这应该可以帮助您解决以下问题:
Launch a completely independent process
我认为您对PIPE想要达到的目标有很好的解释。

关于python - 以apache(python app)作为独立进程启动nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63042227/

相关文章:

php - 访问 Web 服务器文档根文件夹上方的文件

docker - 从多个容器创建单个Docker镜像

Python - 类型对象 'str' 没有属性 'string'

python - Django url参数传递

python - 哪个网络服务器与 Django 一起使用? (更新于 2011 年使用)

apache - .htaccess到其他端口的特定URL

python - 从 7.1.2 安装 pip 8.1.1 时出现问题

python-分割数据集以获得高性能准确性的最佳技术

sockets - 两个 Unicorn 服务器如何绑定(bind)到同一个 Unix 套接字?

django - 将 Nginx 设置为 Apache 的反向代理与 Apache Event MPM 的反向代理