Python self-enabled HTTP server python server

Start Web Service
1. Basic approaches
Python has its own simple server program, which can easily open the service.
Command in python3 to #python3-m http.server, or python-m http.server 80

Command in python2 as# python -m SimpleHTTPServer 8000

  1. cd www directory
  2. python -m http.server
    Turns on successfully, the output “Serving HTTP on 0.0.0.0 port 8000″http://0.0.0.0:8000/) … means the service is open at the 8,000 port of this machine.
    If you need to run backstage, add it after the order.”&”The symbol, Ctrl+C will not close the service as follows:

python -m http.server &
If the service is to be maintained, nohup will be added before the order in order to ignore all the suspension signals as follows:

nohup python -m http.server 8001
2. Specify port
If the default port is not used, you can attach port parameters to the opening, such as:

python -m http.server 8001
The service will be open at the 8001 port.

Use Web services
Availablehttp://0.0.0.0:8000/查看www目录下的网页文件,若无index.html则会显示目录下的文件。
You can also view the IP of this machine using a fconfig command.

1. Python on the http server
python -m SimpleHTTPServer 8080
If hint is wrong:
python.exe: No module named SimpleHTTPServer

Let’s try the command:
python -m http.server

2. Execute py script file, open cgi map

python -m http.server –cgi 8000

Add in py code

header = ‘Content-Type: text/html\n’
print(header)

For example, the document code/cgi-bin/1.py:

header = ‘Content-Type: text/html\n’
html = ‘abc’
print(header)
print(html)

Visitshttp://127.0.0.1:8000/cgi-bin/1.py

Normal output abc

Ps:

The default directory for py-code files is in cgi-bin or htbin

未经允许不得转载:萌萌Apprentissage » Python self-enabled HTTP server python server

Like (0) 打赏

Comments 0

Protected with IP Blacklist CloudIP Blacklist Cloud
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

//下一个脚本特效
//下一个脚本