简体   繁体   中英

Python http.server Create Multiple Instances

How do you create multiple servers with Python's runtime command python -m http.server ?

The command creates a server based in C://Python/Python35 with index.html as its home base. If you have two folders, how would you create a server for each of the folders.

Edit

You can also do that ouside of the C://Python/Python35 folder if you do python -m http.server . I have figured out how to create multiple servers with @shadow's help, but when I attempt to connect to the server with 192.168.xxx.xxx:8000 it times out, but on my computer, it works. Why can I not connect to the IP?

If you wish to run multiple http.server instances in parallel - you will need to define different port numbers for each.

By default, port 8000 is used, but this can be overridden on the command line like so;

python -m http.server 8001

This server will run on port 8001 instead of the default.

Now all you have to do is run this command from whatever directories you want shared in this manner, with a different port for each one. One way to do this, is to use cmd.exe to navigate to the folder you wish to expose, then run the command from there.

If you do not have python in your PATH, then using

C:\Python\Python35\python.exe -m http.server 8002

for example should do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM