Dre*_*kes 289 command-line command-line-tool simplehttpserver httpserver
Python的http.server(或Python的SimpleHTTPServer)是从命令行提供当前目录内容的好方法:
python -m http.server
Run Code Online (Sandbox Code Playgroud)
但是,就网络服务器而言,它非常低调......
它表现得好像是单线程的,并且在使用RequireJS加载JavaScript AMD模块时偶尔会导致超时错误.加载一个没有图像的简单页面可能需要五到十秒钟.
什么是更快的替代方案,同样方便?
Dre*_*kes 379
node.js的http-server非常方便,比Python的SimpleHTTPServer快得多.这主要是因为它使用异步IO来并发处理请求,而不是序列化请求.
如果你还没有安装node.js.然后使用节点包管理器(npm
)来安装包,使用-g
全局安装选项.如果您使用的是Windows,则需要具有管理员权限的提示,而在Linux/OSX上,您需要使用sudo
以下命令:
npm install http-server -g
Run Code Online (Sandbox Code Playgroud)
这将下载任何所需的依赖项并安装http-server
.
现在,从任何目录,您可以键入:
http-server [path] [options]
Run Code Online (Sandbox Code Playgroud)
路径是可选的,默认为./public
是否存在,否则./
.
选项是[默认值]:
-p
收听的端口号[8080]-a
要绑定到[localhost]的主机地址-i
显示目录索引页[True]-s
或--silent
静音模式不会登录到控制台-h
或--help
显示帮助信息并退出因此,要在端口8000上提供当前目录,请键入:
http-server -p 8000
Run Code Online (Sandbox Code Playgroud)
Pet*_*son 103
我推荐:Twisted(http://twistedmatrix.com)
一个用Python编写并根据开源MIT许可证授权的事件驱动的网络引擎.
它是跨平台的,自10.5以来就预装在OS X上.除此之外,您还可以在当前目录中启动一个简单的Web服务器:
twistd -no web --path=.
Run Code Online (Sandbox Code Playgroud)
选项说明(参见twistd --help
更多信息):
-n, --nodaemon don't daemonize, don't use default umask of 0077
-o, --no_save do not save state on shutdown
Run Code Online (Sandbox Code Playgroud)
"web"是一个在Twisted异步引擎之上运行简单Web服务器的Command.它还接受命令行选项(在"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.
Run Code Online (Sandbox Code Playgroud)
还有一堆其他命令,例如:
conch A Conch SSH service.
dns A domain name server.
ftp An FTP server.
inetd An inetd(8) replacement.
mail An email service
... etc
Run Code Online (Sandbox Code Playgroud)
Ubuntu的
sudo apt-get install python-twisted-web (or python-twisted for the full engine)
Run Code Online (Sandbox Code Playgroud)
Mac OS-X(自10.5以来预装,或在MacPorts中可用)
sudo port install py-twisted
Run Code Online (Sandbox Code Playgroud)
视窗
installer available for download at http://twistedmatrix.com/
Run Code Online (Sandbox Code Playgroud)
Twisted还可以利用安全证书来加密连接.将其与现有--path
和--port
(对于普通HTTP)选项一起使用.
twistd -no web -c cert.pem -k privkey.pem --https=4433
Run Code Online (Sandbox Code Playgroud)
pd4*_*d40 27
走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 Code Online (Sandbox Code Playgroud)
使用go run myserver.go
或运行此源来构建可执行文件go build myserver.go
Hud*_*don 21
尝试使用webfs,它很小,并且不依赖于安装node.js或python这样的平台.
Dre*_*kes 14
如果使用Mercurial,则可以使用内置的HTTP服务器.在您要提供的文件夹中:
hg serve
Run Code Online (Sandbox Code Playgroud)
来自文档:
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
Run Code Online (Sandbox Code Playgroud)
gma*_*man 11
安装完成后,您可以通过在Chrome中创建新标签并点击左上角附近的应用按钮来运行它
它有一个简单的gui.单击选择文件夹,然后单击http://127.0.0.1:8887
链接
https://www.youtube.com/watch?v=AK6swHiPtew
还要考虑devd一个用go编写的小型web服务器.这里提供了许多平台的二进制文件.
devd -ol path/to/files/to/serve
Run Code Online (Sandbox Code Playgroud)
它小巧,快速,并提供一些有趣的可选功能,如文件更改时的实时重新加载.
我觉得python -m http.server
不可靠 - 有些回复需要几秒钟.
现在我使用名为Ran https://github.com/m3ng9i/ran的服务器
Ran:用Go编写的简单静态Web服务器
小智 5
尝试波尔佩塔...
npm install -g polpetta
那么你也能
波波塔〜/文件夹
你准备好了:-)
归档时间: |
|
查看次数: |
121761 次 |
最近记录: |