Home > Backend Development > Python Tutorial > How to install http server in python

How to install http server in python

(*-*)浩
Release: 2019-07-09 10:25:59
Original
7933 people have browsed it

On a Linux server or a machine with Python installed, Python comes with a WEB server SimpleHTTPServer.

We can easily use python -m SimpleHTTPServer to quickly build an http service and provide a web service for file browsing.

How to install http server in python

The command is as follows: (Recommended learning: Python video tutorial)

python3 -m http.server
Copy after login

or

python -m SimpleHTTPServer 8000
Copy after login

Use the above command to publish the current directory to port 8000.

But this command is currently running, not in the background. That is to say, if Ctrl C, the port will be closed.

python -m SimpleHTTPServer 8000 &
Copy after login

Add an & at the end of the above command, then the process generated by the command will run in the background and will not affect the use of the current terminal (we are in an environment with only one bash).

The new process generated is the child process of the current bash, so when we close the current bash, the corresponding child process will also be killed, which is not the result we want.

nohup python -m SimpleHTTPServer 8000 &
Copy after login

Add a nohup at the beginning of the command to ignore all hangup signals. If the current bash is closed, the current process will be mounted to the init process and become its child process. In this way, even if the current user exits, other Port 8000 can also be used.

For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to install http server in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template