Python中自带http服务器程序
Python2:SimpleHTTPServer
Python3:http.server
基本使用
- 在python3中使用方法是在web目录下运行命令:
python -m http.server - 如果需要后台运行,可在命令后加"&"符号,Ctrl+C不会关闭服务如下:
python -m http.server & - 如果要保持服务,则在命令前加nohup以忽略所有挂断信号,如下:
nohup python -m http.server
nohup报错
- 注意:nohup python -m http.server 命令可能会报错:
-nohup: ignoring input and appending output to ‘nohup.out’ - 原因:利用nohup命令让脚本程序自己运行,但是nohup他必然会产生日志文件,所以这需要我们将日志文件写到一个文件里面去,默认是写入到nohup.out中,但文件没有写入权限,一般就算你用sudo chmod给文件加权限也没用。
- 解决:
把nohup日志输入到 /dev/null 这个特别的文件下面,它像一个linux黑洞,所有重定向到它的信息都会自动消失。如果你的输入日志很重要的话就不建议重定向到/dev/null中了。
命令:nohup python -m http.server > /dev/null 2> /dev/null &
参考链接:
https://blog.csdn.net/SPACESTUDIO/article/details/86760104
https://blog.csdn.net/qq_37788081/article/details/83825918