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

智能推荐

java比较器Comparator 和 Comparable 的区别-程序员宅基地

文章浏览阅读51次。算了还是给个链接吧 他写的比我的好https://www.cnblogs.com/zyaizz/p/3605103.htmlhttps://blog.csdn.net/u012289441/article/details/45154401?ref=myread楼下这个写得更好鉴定完毕转载于:https://www.cnblogs.com/oushiyang/p/8316146.html...

浅谈后端语言优缺点-程序员宅基地

文章浏览阅读315次。浅谈后端语言优缺点 兄弟连教育在前不久,回答了一个关于后端语言选型的问题,那么后端语言都有哪些,存在什么样的优缺点?因此兄弟连与大家分享一下心得。 语言优缺点..._后端开发语言优缺点

Hadoop集群如何启动_hadoop集群启动命令-程序员宅基地

文章浏览阅读3.4k次。辅助namenode上的resourcemanager通过start-all.sh可能启动不了,需要进入辅namenode上手动启动(/opt/app/hadoop/sbin/hadoop-daemon.sh startresourcemanager)/opt/app/zookeeper-3.4.6/bin/zkServer.sh start(启动)/opt/app/hadoop/sbin/start-all.sh(启动)/opt/app/hadoop/sbin/start-all.sh(停止)_hadoop集群启动命令

打开别人的工程提示IAR版本不兼容问题_win7 iar 8.4无法加载工程-程序员宅基地

文章浏览阅读718次。打开别人的工程提示IAR版本不兼容问题IAR 版本不兼容问题IAR 版本不兼容问题我使用的是 STM32CUBEMX 生成的IAR工程,我自己的是 IAR 版本 8.4,打开别人的工程 8.3版本,但是提示我打开的工程版本更高,可能是IAR的一个bug吧,把cube 生成的 IAR 工程删除 然后再重新生成一个工程就好了。..._win7 iar 8.4无法加载工程

使用VMware安装Ubuntu虚拟机 - 完整教程-程序员宅基地

文章浏览阅读4.8w次,点赞89次,收藏590次。使用 VMware Workstation 16 Pro 安装 Ubuntu 虚拟机 - 完整教程_vmware安装ubuntu

商业WIFI,移动互联网的一大超级入口-程序员宅基地

文章浏览阅读116次。在2016中国互联网大会之中国WiFi应用创新大会上,中国互联网协会开发者核心价值小组秘书长于立娟发表了精彩的开幕致辞,她指出随着移动上网终端的多元化,WiFi应用已经成为移动互联网时代继浏览器、超级APP之后的又一大超级入口。 于立娟表示,“WiFi如果仅仅停留在底层入口,就会像3G...

随便推点

朴素贝叶斯 Naive Bayes Classifier-程序员宅基地

文章浏览阅读2.1k次,点赞2次,收藏21次。本文主要简单介绍了朴素贝叶斯的基本概念,优缺点,应用场景,建模时的注意事项,模型的评价指标,以及朴素贝叶斯在解决分类任务时的python实现方法和示例等。_朴素贝叶斯

深入理解Java中的HashMap:工作原理、实现方式与使用案例分析_java中hashmap-程序员宅基地

文章浏览阅读1.6k次,点赞3次,收藏9次。HashMap是一种非常常见和实用的数据结构,它被广泛应用于Java编程中。在本文中,我们将深入探讨HashMap的工作原理、实现方式和使用案例,以帮助读者更好地理解和应用这一数据结构。_java中hashmap

HotSpot 垃圾回收-程序员宅基地

文章浏览阅读591次,点赞26次,收藏8次。主要概括了hotspot的gc机制

病毒分析之撒旦(Satan)勒索病毒分析解密(AES256 ECB算法)_撒旦查询恶意-程序员宅基地

文章浏览阅读2.9k次,点赞3次,收藏10次。病毒分析之撒旦(Satan)勒索病毒分析解密(AES256 ECB算法)0x0病毒概况撒旦勒索病毒主要是针对企业服务器用户进行感染加密其服务器上的文件并勒索用户的一种病毒。撒旦病毒通过大量漏洞利用工具,扫描入侵主机。成功入侵后加密重要文件。并生成文件用中英韩三种语言提示索要比特币赎金解密文件。0x1恶意行为1.主模块会释放大量攻击模块并执行,也会连接恶意IP下载病毒文件..._撒旦查询恶意

在Ubuntu20.04配置PX4环境_ubuntu 24.04 ppeizhi-程序员宅基地

文章浏览阅读932次,点赞7次,收藏8次。pwd=5npl 提取码:5npl。找到“软件和更新”,选择aliyun服务器,——>【关闭】——>【重新载入】,等待进度条完毕就更管成功。出现“Configuring incomplete, errors occurred!",这是由于没有将软件源改为国内软件源,如果意外退出下载,第二次进入下载的时候缓存会被锁住。在主目录下打开终端,运行以下命令,_ubuntu 24.04 ppeizhi

关于报错“! [rejected]master -> master (non-fast-forward)”的解决方法_efs/heads/master:refs/heads/master[rejected] (non--程序员宅基地

文章浏览阅读3.2w次,点赞18次,收藏58次。在遇到上述错误自己无解决时,于是开始了网上大搜索:git push -u origin master 上面命令将本地的master分支推送到origin主机,同时指定origin为默认主机,后面就可以不加任何参数使用git push了首先尝试了 命令git push -u origin master -f,然后惊喜地出现了下面错误,不能强制推送到受保护的分支随后就又找到了一个方法:先使用..._efs/heads/master:refs/heads/master[rejected] (non-fast-forward)

推荐文章

热门文章

相关标签