Quick and easy to set up efficient multithreaded http server

  • 2020-06-23 02:39:20
  • OfStack

Last year, I made a note "python quickly build a Super simple web Server", which recorded how to use python to quickly build an http server. However, the simplicity is really very simple, but the defect is too obvious, can not multithread download, greatly restricting the download speed, and the performance is worrying, it is enough to meet a large file.

Tonight, I found a better way, through Node. js http to fast and efficient to build a high-performance server, on github Charlie Robbins Shared a open source project, let everyone can easily set up temporary high-performance http server (github address: https: / / github com/indexzero/http - server)

This http server server can be quickly opened anytime and anywhere. It is easy to use. There is no need to press ctrl+c on the terminal to finish.

Preface:

1. First, the system needs Node.js working environment
2. The Debian9 system I am currently using

1. System installation ES38en. js environment method

The following commands apply to Debian and ubuntu

[

curl -sL https://deb.nodesource.com/setup_5.x | bash -
apt-get install nodejs -y

]

2. Get installation http server from nmp

npm install http-server -g

3. Specific usage

Default port is :8080 open the browser to access http://IP:8080 (execute the following command line to access http: 8080)

1. Use grammar

http-server [web路径] [参数]

Example:

http-server /www/donload -d

After entering the above command, the browser will list all the files in /www/donload as a directory list (a higher-looking list than the Nginx directory list).

2. Description of supported parameters

[

-ES85en specifies the port
-ES87en specifies the ip address, default 0.0.0.0 (ignore, 1 is generally useless)
-ES90en displays a list of directories
-ES92en Display autoIndex (default: "True")
When enabled (default is "False"), it replaces the./public/ some-ES101en. js. gz file version exists and requests to accept the gzip encoding.
-ES110en or --ext default file extension (if not provided) (default: 'html')
-ES114en or --silent controls log information from the output
--cors Enabled CORS with the title Access-ES119en-ES120en-ES121en
-o opens a browser window after starting the server
-c sets the cache to control the cache time in seconds for the maximum age header, such as -c10 for 10 seconds (default is "3600"). To disable caching, use -ES128en-1.
-ES130en or --utc USES the UTC time format in log messages.
-ES134en or --proxy agents cannot resolve all requests for a given url locally. For example: - P http: / / someurl com
-ES142en or --ssl enabled https.
-ES146en or -- path to certssl certificate file (default: ES148en.pem).
-ES151en or -- path to keyssl key file (default: ES153en.pem).
-ES156en or --robots offered/ES158en. txt (default: 'ES160en-ES161en: * \ nDisallow: /')
-ES164en or --help prints this list and exits.

]

Well, that's the end of this article.


Related articles: