Appearance
静态Web服务器
静态Web服务器
静态Web服务器:只能支持纯静态文件,较之apache/nginx更为轻量,不支持后端脚本(php/jsp)的扩展,多用于Web前端应用的开发和调试
http-server
http-server是一个使用javascript编写,基于node.js的静态Web服务器
- 在终端输入:
npm install http-server -g - 在指定的根目录下,新建一个 posts.json ,其中包含博文信息
- 在该根目录下启动服务器:
http-server -c-1 - 在浏览器中成功访问
127.0.0.1:8080 - 关闭 http-server服务: 按快捷键
CTRL-C
http-server 的安装 https://www.cnblogs.com/nolaaaaa/p/9126385.html
http-server配置参数
-p 端口号 (默认 8080)
-a IP 地址 (默认 0.0.0.0)
-d 显示目录列表 (默认 'True')
-i 显示 autoIndex (默认 'True')
-e or --ext 如果没有提供默认的文件扩展名(默认 'html')
-s or --silent 禁止日志信息输出
--cors 启用 CORS via the Access-Control-Allow-Origin header
-o 在开始服务后打开浏览器
-c 为 设置缓存控制max-age头的缓存时间(秒) , 如-c10即 10s (默认 为 '3600'). 禁用缓存, 则使用 -c-1.
-U 或 --utc 使用UTC time 格式化log消息
-P or --proxy 代理无法在本地解决给定网址对所有请求 如: -P http://someurl.com
-S or --ssl 启用 https
-C or --cert ssl证书文件路径 (默认值: cert.pem)
-K or --key ssl密钥文件路径 (默认值: key.pem).
-r or --robots 提供一个 /robots.txt (其内容默认为'User-agent: *\nDisallow: /')
-h or --help 打印此列表并退出
其它
- 更多 https://segmentfault.com/a/1190000039744899
- https://www.npmjs.com/package/serve
- npm install simplehttpserver -g
- python生态的simplehttpserver https://geek-blogs.com/blog/python-simplehttpserver/