Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Quickly build a simple, efficient, multithreaded http server

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Last year, I made a note, "python quickly build an ultra-simple web server", which recorded how to quickly build a http server with python. However, simplicity is indeed very simple, but the defect is too obvious, it can not be downloaded with multiple threads, which greatly restricts the download speed, and the performance is poor, so it is difficult to encounter large files.

Tonight I found a better way to build a high-performance http server quickly and efficiently through Node.js. Charlie Robbins on github shares an open source project that allows everyone to easily build a temporary high-performance http server (github address: https://github.com/indexzero/http-server)

This http server server can be started quickly anytime, anywhere, easy to use, no need to press ctrl+c on the terminal to end, I use IDM to download files easily run 32 threads full 100 megabytes of optical fiber

Foreword:

1. First of all, the system needs Node.js working environment.

2. The Debian9 system I am currently using

1. The method of system installation Node.js environment

The following commands apply to Debian and ubuntu

Curl-sL https://deb.nodesource.com/setup_5.x | bash-

Apt-get install nodejs-y

Second, obtain and install http server from nmp

Npm install http-server-g

III. Specific usage

The default port is: 8080, open a browser to access http://IP:8080 (execute the following command line to access it properly)

1. Use syntax

Http-server [web path] [parameters]

Example:

Http-server / www/donload-d

After entering the above command, the browser will list all the files in the / www/donload directory in the form of a directory list (better than the Nginx directory list)

2. Description of supported parameters

-p designated port

-a specifies the ip address. The default is 0.0.0.0 (ignored, it is generally useless)

-d display directory list

-I display autoIndex (default is "True")

-g or-- gzip when enabled (the default is "False"), it replaces the existence of the. / public/some-file.js.gz version of the. / public/some-file.jsgzip file and requests acceptance of gzip encoding.

-e or-- ext default file extension (if not provided) (default is' html')

-s or-- silent controls log information from the output

-- cors enables CORS through the Access-Control-Allow-Origin header

-o Open the browser window after starting the server

-c sets the cache time (in seconds) that controls the maximum age header, for example,-c10 is 10 seconds (the default is "3600"). To disable caching, use-cmur1.

-U or-- utc uses the UTC time format in log messages.

The-P or-- proxy agent cannot resolve all requests for a given url locally. For example:-P http://someurl.com

-S or-- ssl enables https.

The path to the-C or-- certssl certificate file (default: cert.pem).

The path to-K or-- keyssl key file (default: key.pem).

-r or-- robots provides / robots.txt (default is' User-agent:*\ nDisallow:/')

-h or-- help prints this list and exits.

All right, that's the end of this article.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report