Python的http。server(或SimpleHTTPServer for Python 2)是一个从命令行提供当前目录内容的好方法:

python -m http.server

然而,就网络服务器而言,它是非常缓慢的…

它的行为就像它是单线程的,并且在使用RequireJS加载JavaScript AMD模块时偶尔会导致超时错误。加载一个没有图像的简单页面可能需要5到10秒钟。

还有什么更快更方便的选择吗?


当前回答

我在过去的几年里一直在使用filebrowser,它是我发现的最好的替代品。

我喜欢它的特点:

跨平台:支持Linux、MacOs和Windows(+)。它还支持docker(+)。 下载东西是件轻而易举的事。它可以自动将文件夹转换为zip, tar.gz等,用于传输文件夹。 您可以访问文件或文件夹的每一个用途。

其他回答

如果使用Mercurial,则可以使用内置的HTTP服务器。在您希望提供的文件夹中:

hg serve

从文档中可以看出:

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

Go 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)
    }
}

使用go Run myserver运行这个源代码。去构建一个可执行文件去构建myserver。Go

另一个基于节点的简单命令行服务器

https://github.com/greggman/servez-cli

部分是为了响应http服务器存在的问题,特别是在windows上。

安装

然后安装node.js

npm install -g servez

使用

servez [options] [path]

如果没有路径,它将提供当前文件夹。

默认情况下,它为文件夹路径提供index.html(如果存在的话)。否则,它为文件夹提供目录列表。它还提供CORS报头。你可以选择使用——username= someename——password=somepass开启基本身份验证,也可以使用https。

我在过去的几年里一直在使用filebrowser,它是我发现的最好的替代品。

我喜欢它的特点:

跨平台:支持Linux、MacOs和Windows(+)。它还支持docker(+)。 下载东西是件轻而易举的事。它可以自动将文件夹转换为zip, tar.gz等,用于传输文件夹。 您可以访问文件或文件夹的每一个用途。

我推荐:Twisted (http://twistedmatrix.com)

一个事件驱动的网络引擎,用Python编写,使用开源MIT许可。

它是跨平台的,预装在OS X 10.5到10.12上。除此之外,你可以在当前目录中启动一个简单的web服务器:

twistd -no web --path=.

细节

选项说明(参见twistd -help了解更多):

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

“web”是一个命令,在Twisted异步引擎上运行一个简单的web服务器。它还接受命令行选项(在“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.

还有一堆其他命令,如:

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

安装

Ubuntu

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

Mac OS-X(预安装在10.5 - 10.12,或在MacPorts和通过Pip)

sudo port install py-twisted

窗户

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

HTTPS

Twisted还可以使用安全证书对连接进行加密。将其与现有的——path和——port(用于普通HTTP)选项一起使用。

twistd -no web -c cert.pem -k privkey.pem --https=4433