有什么比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

智能推荐

彻底扒光 通过智能路由器拆解看其本质-程序员宅基地

文章浏览阅读1.7k次。可以看到很多联发科的MT芯片摘自:https://net.zol.com.cn/531/5312999.html彻底扒光 通过智能路由器拆解看其本质2015-07-23 00:40:00[中关村在线 原创] 作者:陈赫|责编:白宁收藏文章 分享到 评论(24)关注智能路由器拆解的朋友们注意啦!我们已经将这五款产品彻底扒开,将主板的真容展现在了大家的眼前。网友们可以看见这些智能路由器主板的做工和用料,我们还为网友们展示了主要的电子元器件,供大家品评观赏。..._路由器拆解

Java--深入JDK和hotspot底层源码剖析Thread的run()、start()方法执行过程_jdk的源码hotspot跟jdk是分开的-程序员宅基地

文章浏览阅读2.1k次,点赞101次,收藏78次。【学习背景】今天主要是来了解Java线程Thread中的run()、start()两个方法的执行有哪些区别,会给出一个简单的测试代码样例,快速理解两者的区别,再从源码层面去追溯start()底层是如何最终调用Thread#run()方法的,个人觉得这样的学习不论对面试,还是实际编程来说都是比较有帮助的。进入正文~学习目录一、代码测试二、源码分析2.1 run()方法2.2 start()方法三、使用总结一、代码测试执行Thread的run()、start()方法的测试代码如下:public_jdk的源码hotspot跟jdk是分开的

透视俄乌网络战之一:数据擦除软件_俄乌网络战观察(一)-程序员宅基地

文章浏览阅读4.4k次,点赞90次,收藏85次。俄乌冲突中,各方势力通过数据擦除恶意软件破坏关键信息基础设施计算机的数据,达到深度致瘫的效果,同时窃取重要敏感信息。_俄乌网络战观察(一)

Maven私服仓库配置-Nexus详解_nexus maven-程序员宅基地

文章浏览阅读1.7w次,点赞23次,收藏139次。Maven 私服是一种特殊的Maven远程仓库,它是架设在局域网内的仓库服务,用来代理位于外部的远程仓库(中央仓库、其他远程公共仓库)。当然也并不是说私服只能建立在局域网,也有很多公司会直接把私服部署到公网,具体还是得看公司业务的性质是否是保密的等等,因为局域网的话只能在公司用,部署到公网的话员工在家里也可以办公使用。_nexus maven

基于AI的计算机视觉识别在Java项目中的使用 (四) —— 准备训练数据_java ocr ai识别训练-程序员宅基地

文章浏览阅读934次。我先用所有的样本数据对模型做几轮初步训练,让深度神经模型基本拟合(数万条记录的训练集,识别率到99%左右),具备初步的识别能力,这时的模型就是“直男”。相较于训练很多轮、拟合程度很高的“油腻男”,它的拟合程度较低,还是“直男愣头青”。..............._java ocr ai识别训练

hibernate 数据库类型 date没有时分秒解决_hibernate解析時間只有年月日沒有時分秒-程序员宅基地

文章浏览阅读688次。一、问题现象:  在数据库表中日期字段中存的日期光有年月日,没有时分秒。二、产生原因:三 解决办法   检查表的相应映射xml文件。 <property name="operateDate" type="Date">如果同上面所写,那问题出在 type类型上了正确写法 :<property name="operateDate" type="java.util..._hibernate解析時間只有年月日沒有時分秒

随便推点

springbbot运行无法编译成功,找不到jar包报错:Error:(3, 46) java: 程序包org.springframework.context.annotation不存在-程序员宅基地

文章浏览阅读1k次,点赞2次,收藏2次。文章目录问题描述:解决方案:问题描述:提示:idea springbbot运行无法编译成功,找不到jar包报错E:\ideaProject\demokkkk\src\main\java\com\example\demo\config\WebSocketConfig.javaError:(3, 46) java: 程序包org.springframework.context.annotation不存在Error:(4, 46) java: 程序包org.springframework.conte_error:(3, 46) java: 程序包org.springframework.context.annotation不存在

react常见面试题_recate面试-程序员宅基地

文章浏览阅读6.4k次,点赞6次,收藏36次。1、redux中间件中间件提供第三方插件的模式,自定义拦截 action -&gt; reducer 的过程。变为 action -&gt; middlewares -&gt; reducer 。这种机制可以让我们改变数据流,实现如异步 action ,action 过滤,日志输出,异常报告等功能。常见的中间件:redux-logger:提供日志输出redux-thunk:处理异步操作..._recate面试

交叉编译jpeglib遇到的问题-程序员宅基地

文章浏览阅读405次。由于要在开发板中加载libjpeg,不能使用gcc编译的库文件给以使用,需要自己配置使用另外的编译器编译该库文件。/usr/bin/ld:.libs/jaricom.o:RelocationsingenericELF(EM:40)/usr/bin/ld:.libs/jaricom.o:RelocationsingenericELF(EM:40)...._jpeg_utils.lo: relocations in generic elf (em: 8) error adding symbols: file

【办公类-22-06】周计划系列(1)“信息窗” (2024年调整版本)-程序员宅基地

文章浏览阅读578次,点赞10次,收藏17次。【办公类-22-06】周计划系列(1)“信息窗” (2024年调整版本)

SEO优化_百度seo resetful-程序员宅基地

文章浏览阅读309次。SEO全称为Search Engine Optimization,中文解释为搜索引擎优化。一般指通过对网站内部调整优化及站外优化,使网站满足搜索引擎收录排名需求,在搜索引擎中提高关键词排名,从而把精准..._百度seo resetful

回归预测 | Matlab实现HPO-ELM猎食者算法优化极限学习机的数据回归预测_猎食者优化算法-程序员宅基地

文章浏览阅读438次。回归预测 | Matlab实现HPO-ELM猎食者算法优化极限学习机的数据回归预测_猎食者优化算法

推荐文章

热门文章

相关标签