有什么比Python的http.server(或SimpleHTTPServer)更快的替代方法?_有没有类似python http server的工具-程序员宅基地

技术标签: simplehttpserver  command-line  httpserver  command-line-tool  

本文翻译自:What is a faster alternative to Python's http.server (or SimpleHTTPServer)?

Python's http.server (or SimpleHTTPServer for Python 2) is a great way of serve the contents of the current directory from the command line: Python的http.server (或适用于Python 2的SimpleHTTPServer)是一种从命令行提供当前目录内容的好方法:

python -m http.server

However, as far as web servers go, it's very slooooow... 但是,就Web服务器而言,它是非常简单的...

It behaves as though it's single threaded, and occasionally causes timeout errors when loading JavaScript AMD modules using RequireJS. 它的行为就好像是单线程的一样,并且在使用RequireJS加载JavaScript AMD模块时偶尔会导致超时错误。 It can take five to ten seconds to load a simple page with no images. 加载没有图像的简单页面可能需要五到十秒钟。

What's a faster alternative that is just as convenient? 有什么方便的更快替代方法?


#1楼

参考:https://stackoom.com/question/S9i2/有什么比Python的http-server-或SimpleHTTPServer-更快的替代方法


#2楼

http-server for node.js is very convenient, and is a lot faster than Python's SimpleHTTPServer. 用于node.js的http服务器非常方便,并且比Python的SimpleHTTPServer快得多。 This is primarily because it uses asynchronous IO for concurrent handling of requests, instead of serialising requests. 这主要是因为它使用异步IO并发处理请求,而不是序列化请求。

Installation 安装

Install node.js if you haven't already. 如果尚未安装,请安装node.js。 Then use the node package manager ( npm ) to install the package, using the -g option to install globally. 然后使用节点软件包管理器( npm )安装软件包,并使用-g选项进行全局安装。 If you're on Windows you'll need a prompt with administrator permissions, and on Linux/OSX you'll want to sudo the command: 如果您使用Windows,则需要具有管理员权限的提示,而在Linux / OSX上,您将需要sudo命令:

npm install http-server -g

This will download any required dependencies and install http-server . 这将下载所有必需的依赖项并安装http-server

Use 采用

Now, from any directory, you can type: 现在,您可以从任何目录键入:

http-server [path] [options]

Path is optional, defaulting to ./public if it exists, otherwise ./ . 路径是可选的,如果存在则默认为./public ,否则为./

Options are [defaults]: 选项为[默认值]:

  • -p The port number to listen on [8080] -p要侦听的端口号[8080]
  • -a The host address to bind to [localhost] -a绑定到[localhost]的主机地址
  • -i Display directory index pages [True] -i显示目录索引页[是]
  • -s or --silent Silent mode won't log to the console -s--silent静默模式不会登录到控制台
  • -h or --help Displays help message and exits -h--help显示帮助消息并退出

So to serve the current directory on port 8000, type: 因此,要在端口8000上提供当前目录,请键入:

http-server -p 8000

#3楼

If you use Mercurial, you can use the built in HTTP server. 如果您使用Mercurial,则可以使用内置的HTTP服务器。 In the folder you wish to serve up: 在您要投放的文件夹中:

hg serve

From the docs : 文档

export the repository via HTTP

    Start a local HTTP repository browser and pull server.

    By default, the server logs accesses to stdout and errors to
    stderr. Use the "-A" and "-E" options to log to files.

options:

 -A --accesslog       name of access log file to write to
 -d --daemon          run server in background
    --daemon-pipefds  used internally by daemon mode
 -E --errorlog        name of error log file to write to
 -p --port            port to listen on (default: 8000)
 -a --address         address to listen on (default: all interfaces)
    --prefix          prefix path to serve from (default: server root)
 -n --name            name to show in web pages (default: working dir)
    --webdir-conf     name of the webdir config file (serve more than one repo)
    --pid-file        name of file to write process ID to
    --stdio           for remote clients
 -t --templates       web templates to use
    --style           template style to use
 -6 --ipv6            use IPv6 in addition to IPv4
    --certificate     SSL certificate file

use "hg -v help serve" to show global options

#4楼

give polpetta a try ... 尝试波尔佩塔...

npm install -g polpetta npm install -g polpetta

then you can 那么你也能

polpetta ~/folder 波波塔〜/文件夹

and you are ready to go :-) 你准备好了:-)


#5楼

1.0 includes a http server & util for serving files with a few lines of code. 1.0包含一个http服务器util,用于通过几行代码来提供文件

package main

import (
    "fmt"; "log"; "net/http"
)

func main() {
    fmt.Println("Serving files in the current directory on port 8080")
    http.Handle("/", http.FileServer(http.Dir(".")))
    err := http.ListenAndServe(":8080", nil)
    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}

Run this source using go run myserver.go or to build an executable go build myserver.go 使用go run myserver.go来运行此源,或构建可执行文件go build myserver.go


#6楼

I recommend: Twisted ( http://twistedmatrix.com ) 我建议: Twistedhttp://twistedmatrix.com

an event-driven networking engine written in Python and licensed under the open source MIT license. 一个事件驱动的网络引擎,该引擎使用Python编写,并已获得MIT开源许可。

It's cross-platform and was preinstalled on OS X 10.5 to 10.12. 它是跨平台的,已预先安装在OS X 10.5至10.12上。 Amongst other things you can start up a simple web server in the current directory with: 除其他外,您可以使用以下命令在当前目录中启动一个简单的Web服务器:

twistd -no web --path=.

Details 细节

Explanation of Options (see twistd --help for more): 选项说明(有关更多信息,请参见twistd --help ):

-n, --nodaemon       don't daemonize, don't use default umask of 0077
-o, --no_save        do not save state on shutdown

"web" is a Command that runs a simple web server on top of the Twisted async engine. “ web”是在Twisted异步引擎之上运行简单Web服务器的命令。 It also accepts command line options (after the "web" command - see twistd web --help for more): 它还接受命令行选项(在“ web”命令之后-有关更多信息,请参见twistd web --help ):

  --path=             <path> is either a specific file or a directory to be
                      set as the root of the web server. Use this if you
                      have a directory full of HTML, cgi, php3, epy, or rpy
                      files or any other files that you want to be served up
                      raw.

There are also a bunch of other commands such as: 还有很多其他命令,例如:

conch            A Conch SSH service.
dns              A domain name server.
ftp              An FTP server.
inetd            An inetd(8) replacement.
mail             An email service
... etc

Installation 安装

Ubuntu 的Ubuntu

sudo apt-get install python-twisted-web (or python-twisted for the full engine)

Mac OS-X (comes preinstalled on 10.5 - 10.12, or is available in MacPorts and through Pip) Mac OS-X(预先安装在10.5-10.12上,或者可通过MacPorts和通过Pip获得)

sudo port install py-twisted

Windows 视窗

installer available for download at http://twistedmatrix.com/

HTTPS HTTPS

Twisted can also utilise security certificates to encrypt the connection. Twisted还可以利用安全证书来加密连接。 Use this with your existing --path and --port (for plain HTTP) options. 与现有的--path--port (对于纯HTTP)选项一起使用。

twistd -no web -c cert.pem -k privkey.pem --https=4433
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xfxf996/article/details/107742576

智能推荐

一个ngrok如何穿透多个端口?_ngrok多个端口-程序员宅基地

文章浏览阅读2.7k次,点赞2次,收藏4次。如何不充钱就可以穿透多个端口?./ngrok authtoken 授权码之前这个操作的生成的yml文件中修改 端口可添加多个addr:port端口可随意配置_ngrok多个端口

C语言 char转uint8_t-程序员宅基地

文章浏览阅读5.9k次。char转uint8_t:static int char2uint(char *input, uint8_t *output){ for(int i = 0; i < 24; i++) { output[i] &= 0x00; for (int j = 1; j >= 0; j--) { char hb = input[i*2 + 1 - j]; if (hb >= '0' &..._char转uint8_t

android 陀螺仪简单使用,判读手机是否静止状态_安卓陀螺仪多少才算静止-程序员宅基地

文章浏览阅读6.5k次,点赞5次,收藏13次。陀螺仪允许您在任何给定时刻确定Android设备的角速度。简单来说,它告诉您设备绕X,Y和Z轴旋转的速度有多快。最近,即使是预算手机正在制造,陀螺仪内置,增强现实和虚拟现实应用程序变得如此受欢迎。通过使用陀螺仪,您可以开发可以响应设备方向的微小更改的应用程序。创建陀螺仪对象和管理器manager// Register it, specifying the polling interv..._安卓陀螺仪多少才算静止

lib静态库逆向分析_libtersafe-程序员宅基地

文章浏览阅读4.7k次,点赞3次,收藏16次。当我们要分析一个lib库里的代码时,首先需要判断这是一个静态库还是一个导入库。库类型判断lib文件其实是一个压缩文件。我们可以直接使用7z打开lib文件,以查看里面的内容。如果里面的内容是obj文件,表明是静态库。如果里面的内容是dll文件,表明是导入库。导入库里面是不包含代码的,代码包含在对应的dll文件中。从lib中提取obj静态库是一个或者多个obj文件的打包,这里有两个方法从中提取obj:Microsoft 库管理器 7z解压Microsoft 库管理器(li_libtersafe

Linux的网络适配器_linux 查询网络适配器-程序员宅基地

文章浏览阅读5.3k次,点赞3次,收藏3次。了解一下,省的脑壳痛 桥接模式对应的虚拟网络名称“VMnet0” 桥接模式下,虚拟机通过主机的网卡进行通信,若物理主机有多块网卡(有线的和无线网卡),应选择桥结哪块物理网卡桥接模式下,虚拟机和物理主机同等地位,可以通过物理主机的网卡访问外网(局域网),一个局域网的其他计算机可以访问虚拟机。为虚拟机设置一个与物理网卡在同个网段的IP,则虚拟机就可以与物理主机以及局域..._linux 查询网络适配器

【1+X Web前端等级考证 】 | Web前端开发中级理论 (附答案)_1+xweb前端开发中级-程序员宅基地

文章浏览阅读3.4w次,点赞77次,收藏438次。# 前言2020 12月 1+X Web 前端开发中级 模拟题大致就更这么多,我的重心不在这里,就不花太多时间在这里面了。但是,说说1+X Web前端开发等级考证这个证书,总有人跑到网上问:这个证书有没有用? 这个证书含金量高不高?# 关于考不考因为这个是工信部从2019年才开始实施试点的,目前还在各大院校试点中,就目前情况来看,知名度并不是很高,有没有用现在无法一锤定音,看它以后办的怎么样把,软考以前也是慢慢地才知名起来。能考就考吧,据所知,大部分学校报考,基本不用交什么报考费(小部分学校,个别除._1+xweb前端开发中级

随便推点

项目组织战略管理及组织结构_项目组织的具体形态的是战略管理层-程序员宅基地

文章浏览阅读1.7k次。组织战略是组织实施各级项目管理,包括项目组合管理、项目集管理和项目管理的基础。只有从组织战略的高度来思考,思考各个层次项目管理在组织中的位置,才能够理解各级项目管理在组织战略实施中的作用。同时战略管理也为项目管理提供了具体的目标和依据,各级项目管理都需要与组织的战略保持一致。..._项目组织的具体形态的是战略管理层

图像质量评价及色彩处理_图像颜色质量评价-程序员宅基地

文章浏览阅读1k次。目录基本统计量色彩空间变换亮度变换函数白平衡图像过曝的评价指标多视影像因曝光条件不一而导致色彩差异,人眼可以快速区分影像质量,如何利用图像信息辅助算法判断影像优劣。基本统计量灰度均值方差梯度均值方差梯度幅值直方图图像熵p·log(p)色彩空间变换RGB转单通道灰度图像 mean = 225.7 stddev = 47.5mean = 158.5 stddev = 33.2转灰度梯度域gradMean = -0.0008297 / -0.000157461gr_图像颜色质量评价

MATLAB运用规则,利用辛普森规则进行数值积分-程序员宅基地

文章浏览阅读1.4k次。Simpson's rule for numerical integrationZ = SIMPS(Y) computes an approximation of the integral of Y via the Simpson's method (with unit spacing). To compute the integral for spacing different from one..._matlab利用幸普生计算积分

【AI之路】使用huggingface_hub优雅解决huggingface大模型下载问题-程序员宅基地

文章浏览阅读1.2w次,点赞28次,收藏61次。Hugging face 资源很不错,可是国内下载速度很慢,动则GB的大模型,下载很容易超时,经常下载不成功。很是影响玩AI的信心。经过多次测试,终于搞定了下载,即使超时也可以继续下载。真正实现下载无忧!究竟如何实现?且看本文分解。_huggingface_hub

mysql数据库查看编码,mysql数据库修改编码_查看数据库编码-程序员宅基地

文章浏览阅读3.5k次,点赞2次,收藏7次。其中 `DEFAULT CHARSET` 和 `COLLATE` 分别指定了表的默认编码和排序规则。其中 `DEFAULT CHARACTER SET` 指定了数据库的默认编码。其中 `Collation` 列指定了字段的排序规则,这也是字段的默认编码。此命令将更改表的默认编码和排序规则。此命令将更改字段的编码和排序规则。此命令将更改数据库的默认编码。_查看数据库编码

机器学习(十八):Bagging和随机森林_bagging数据集-程序员宅基地

文章浏览阅读1.3k次,点赞7次,收藏24次。本文深入探讨了集成学习及其在随机森林中的应用。对集成学习的基本概念、优势以及为何它有效做了阐述。随机森林,作为一个集成学习方法,与Bagging有紧密联系,其核心思想和实现过程均在文中进行了说明。还详细展示了如何在Sklearn中利用随机森林进行建模,并对其关键参数进行了解读,希望能帮助大家更有效地运用随机森林进行数据建模。_bagging数据集