admin管理员组

文章数量:1535051

OpenWRT 路由器实现浏览器下载文件到计算机

在从路由器中下载文件时要用到此功能,比如说要备份路由器中的配置文件,下载路由器中的日志到本地等等都需要使用到该方法

要下载路由器中的文件到本地,最好的方法是在路由器中搭建一个http服务器

路由器中搭建http服务器的软件有很多,今天我们说uhttpd这个软件,openwrt自带的应该就是这个,因为luci管理界面需要用到它,因此不需要额外再安装了,比较方便

查看现有的http服务

路由器中一般都有现成的http服务程序,因为luci web管理界面需要用到它
在路由器中输入ps | grep uhttpd,可以看到如下两个进程,第一个为系统自带,用来提供web界面的访问,第二个则是我后面加入的用来做文件传输服务的,下面我们来介绍配置uhttp的方法

root@Router:~# ps | grep uhttpd
 1307 root      1600 S    /usr/sbin/uhttpd -f -h /www -r KFRouter -x /cgi-bin -u /ubus -t 60 -T 30 -k 2
 1308 root      1148 S    /usr/sbin/uhttpd -f -h /download -r KFRouter -x /cgi-bin -n 3 -p 0.0.0.0:81
19069 root      1472 S    grep uhttpd

配置uhttpd服务

在路由器中输入cat /etc/config/uhttpd得到如下信息,其中 uhttpd ‘main’的section为提供web界面的配置,而uhttpd ‘download’则是我们为文件下载配置的服务,

  • 其中listen_http的值填写0.0.0.0:8181就是http服务要监听的端口,下载文件时的端口要写对,0.0.0.0指向路由器网关地址
  • 其中home的值为web服务器的路径,只用该路径下的文件才能被下载
  • 比如现在我要下载路由器中/download/test.log文件,那么只需要在浏览器中输入http://192.168.X.X:81/test.log即可(其中192.168.X.X为路由器网关地址)
config uhttpd 'main'
    list listen_http '0.0.0.0:80'
    list listen_http '[::]:80'
    list listen_https '0.0.0.0:443'
    list listen_https '[::]:443'
    option redirect_https '1'
    option home '/www'
    option rfc1918_filter '1'
    option max_requests '3'
    option max_connections '100'
    option cert '/etc/uhttpd.crt'
    option key '/etc/uhttpd.key'
    option cgi_prefix '/cgi-bin'
    option script_timeout '60'
    option network_timeout '30'
    option http_keepalive '20'
    option tcp_keepalive '1'
    option ubus_prefix '/ubus'

config cert 'px5g'
    option days '730'
    option bits '1024'
    option country 'ZZ'
    option state 'Somewhere'
    option location 'Uknown'
    option commonname 'OpenWrt'

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

配置修改完毕后重启服务

配置修改后使用/etc/init.d/uhttpd restart重启服务就可以了

本文标签: 路由器浏览器计算机文件OpenWRT