ubuntu20.04安装测试uhttpd

uhttpd是openwrt上运行一个高效小型Http服务,支持cgi, lua等特性。可以直接通过snap方式安装,如果是16.04,18.04或者20.04,snap已经默认安装了;如果是其它版本,需要先安装snap: sudo apt install snapd

然后安装:

sudo snap install uhttpd

默认80端口,为避免与apache2冲突,可以修改成其它端口,如8086:

sudo snap set uhttpd listening-port=8086

默认根目录在/var/snap/uhttpd/common,通过set方法修改好像不成功:sudo snap set uhttpd document-root-dir=/media/USB

然后通过snap命令启动即可:

$ snap run uhttpd 
2021/01/03 17:24:14 Serving "/var/snap/uhttpd/common"
2021/01/03 17:24:14 Listening on ":8086"

可以在命令后面加上&号(snap run uhttpd &)以后台方式执行。

当然了,上面使用的是默认选项,也可以直接以参数指定方式修改这些默认选项,如端口、根目录等,如:uhttpd -dir=/home/user/www -addr="127.0.0.1:8080"

更多用法:

Usage of uhttpd:
  -addr=":80": The ADDRESS:PORT to listen on
  -dir="": The directory to serve up
  -log=false: Enable/disable logging
  -log-path="": Log to file (leave blank for STDOUT)
  -log-prefix="uhttpd": Set the logging prefix

-addr="..." lets you set the IPv4 address and port uhttp listens on.

-dir="..." tells uhttpd which directory to serve files out of.

-log tells uhttpd to log requests for files.

-log-path="..." is an optional flag, and lets you specify the name of a file to write your request logs to. If you do not specify a log file, the request logs are written to standard output (STDOUT).

-log-prefix="..." is another optional flag, that lets you specify the logging prefix; by default, the logging prefix is "uhttpd".

More detail: https://github.com/nesv/uhttpd

 

posted on 2021-01-03 17:19  wzc0066  阅读(1009)  评论(0编辑  收藏  举报