Python-BaseHTTP在启动nginx或其他服务时被攻击

2024-03-29 06:37:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用BaseHTTP,因为它非常简单。如果我用错了,请给我建议。你知道吗

if self.path.endswith("nginxstart"):
    xxxxxx 
    status=os.system("/home/karthik/nginx/nginx-1.0.4/sbin/nginx");  #tried ls -l and works
    self.wfile.write("nginx restarted")

nginx启动了,但在我关闭python服务器之前,不会将“nginx restarted”写入浏览器。 当我执行netstat-anp | grep'nginx's pid'时,有两个侦听端口:

  1. python服务器正在监听(端口8000:我已经杀死了它)
  2. nginx应该在上面运行。你知道吗

如果我运行简单的shell命令,效果会很好操作系统(“ls-l”)等等。你知道吗

如果我像普通的python脚本一样运行,而不是像web服务器那样运行,效果会很好。你知道吗

尝试启动一些其他服务也不起作用。 我试了试抓,抓的部分没有被执行。 浏览器永远处于连接/接收状态。你知道吗

有什么帮助吗?你知道吗


Tags: path端口self服务器if浏览器nginxls
1条回答
网友
1楼 · 发布于 2024-03-29 06:37:32

你的代码被卡住是因为操作系统阻止,直到命令完成。因此,如果nginx命令不在后台,进程将不会结束,代码将被卡住。你知道吗

另一种方法是使用^{}模块:

from subprocess import Popen

# start a new command
cmd = Popen("/home/.../nginx", shell=True)

# you can regulary check if the command is still running with:
cmd.poll()
if cmd.returncode is None:
    print "process is still running !"
else:
    print "process exited with code %d" % cmd.returncode

# or even kill it
cmd.kill()

相关问题 更多 >