uhttpd使用

本文介绍了如何管理和配置uhttpd服务,包括启动、停止、重启和重新加载配置文件。通过修改/uetc/config/uhttpd配置,可以监听多个端口,并允许通过http://ip:81/访问到特定目录。此外,还提到了CGI脚本的配置,如cgi_prefix和lua_prefix,以及/home、/key和/crt选项的作用。提供了多个相关脚本和资源链接供进一步学习。
root@router:/www# /etc/init.d/uhttpd status // 并没有status这个子命令

Syntax: /etc/init.d/uhttpd [command]

Available commands:

        start   Start the service

        stop    Stop the service

        restart Restart the service

        reload  Reload configuration files (or restart if that fails)

        enable  Enable service autostart

        disable Disable service autostart

 

root@router:/www# /etc/init.d/uhttpd reload  // 重新加载配置

/etc/init.d/uhttpd  // uhttpd执行脚本,该文件很值得一看

/etc/config/uhttpd // uhttpd运行相关配置

 

uhttpd可以同时监听多个端口

// 在/etc/config/uhttpd加入如下配置,即可通过http://ip:81/访问到/tmp目录

config 'uhttpd' 'tmp'   
        list 'listen_http' '0.0.0.0:81'
        option 'home' '/tmp'
        option 'cgi_prefix' '/cgi-bin'

 

 

root@router:/www# ls  // openwrt默认端口,对应的 Root

cgi-bin              cgi-bin-nodes.html   cgi-bin-status.html  index.html           luci                 luci-static

root@router:/www# du -sh

325.0K  .

 

/etc/confg/uhttpd配置中,和管理界面访问直接相关的一段配置

// 系统是怎么读取这些配置的,配置读取代码在哪个地方?

 

config 'uhttpd' 'main'

        list 'listen_http' '0.0.0.0:80'      // 默认端口设置

        list 'listen_https' '0.0.0.0:443'  // 通过https访问,端口设定

        option 'home' '/www'               // 页面所在的位置

        option 'cert' '/etc/uhttpd.crt'    // https访问对应的证书

        option 'key' '/etc/uhttpd.key'   // 和上面的cert有什么关系?

        option 'cgi_prefix' '/cgi-bin'      //

        option 'script_timeout' '60'

        option 'network_timeout' '30'  

        option 'tcp_keepalive' '1'

        option 'rfc1918_filter' '0'

 

listen_http  只给定端口,则同时绑定IPV4和IPV6地址. :port只绑定IPV4, ::port,同时绑定IPV6.

home 根目录

key    私钥

crt     公钥

cgi_prefix  定义了CGI脚本的前缀,该前缀相对应home路径,如果该字段为空,则cgi功能失效。

lua_prefix  将请求转发给内置的Lua解析器,如果为空,则Lua功能失效。

 

cgi-bin目录下有多个脚本,这些配置和uhttpd的实现紧密相关?

 

root@router:/www# ls cgi-bin -l

-rwxr-xr-x    1 root     root          135 Sep 16  2008 luci

-rwxr-xr-x    1 root     root         2384 Dec 12 01:08 olsr-viz.sh

drwxr-xr-x    2 root     root           32 Apr  2 11:26 splash

-rwxr-xr-x    1 root     root         1432 Dec 12 01:08 vizdata.sh

 

CGI: Perl CGI, PHP CGI, Lua CGI ...

 

 

参考资料

http://news.netcraft.com/archives/2011/04/06/april-2011-web-server-survey.html

https://forum.openwrt.org/search.php?search_id=1586996754

http://wiki.openwrt.org/doc/uci/uhttpd

http://wiki.openwrt.org/doc/howto/http.overview

http://en.wikipedia.org/wiki/Comparison_of_lightweight_web_servers  各种web服务器之比较

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值