首页 > 解决方案 > 如何从 python 脚本重新启动 nginx?

问题描述

我可以使用"nginx -s reload"命令在 shell 上重新启动 nginx。但是,当我使用os.system("nginx -s reload")命令时,它会出现错误。

/usr/local/bin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory 对于这个错误。我已经安装了pcre。是不是有一些魔法问题。

标签: pythonnginx

解决方案


要在 python 脚本中运行此类命令,最好使用subprocess library

试试这个代码而不是你的:

import subprocess
subprocess.call('whatever command you want to run it in terminal', shell=True)

走运


推荐阅读