OpenWrt 默认使用http 访问管理后台,这样不安全,推荐修改为 https 访问,加密数据传输。本文介绍配置步骤
1、卸载旧的ssl软件包
root@OpenWrt:~# opkg remove luci-ssl px5g px5g-mbedtls
这里一定要卸载 px5g
相关的软件包,否则会使用px5g
脚本生成证书,而不是下面的 openssl
2、安装软件包
安装OpenSSL版的luci-ssl
root@OpenWrt:~# opkg update
root@OpenWrt:~# opkg install luci-ssl-openssl libuhttpd-openssl
3、安装OpenSSL
root@OpenWrt:~# opkg install --force-reinstall libustream-openssl openssl-util
如果出现openssl
命令无法正常使用,则安装时增加--force-reinstall
参数强制重装ipk,如下面的错误
root@OpenWrt:~# openssl genrsa -des3 -out root.key 2048
Error relocating /usr/bin/openssl: SSL_get0_next_proto_negotiated: symbol not found
Error relocating /usr/bin/openssl: SSL_CTX_set_next_protos_advertised_cb: symbol not found
Error relocating /usr/bin/openssl: SSL_CTX_set_next_proto_select_cb: symbol not found
Error relocating /usr/bin/openssl: BIO_f_zlib: symbol not found
4、修改uhttp 配置文件
root@OpenWrt:~# vim /etc/config/uhttpd
config uhttpd 'main'
#....
option redirect_https '1' # --> 访问 http 时跳转到 https
list listen_http '0.0.0.0:80'
list listen_https '0.0.0.0:443'
# 配置生成证书时的信息,根据需要修改
config cert 'defaults'
option days '3650'
option bits '2048'
option country 'CN'
option state 'Somewhere'
option location 'sky'
option commonname 'openwrt.lan'
5、修改openssl.cnf
这里可以不修改,可选
root@OpenWrt:~# vim /etc/ssl/openssl.cnf
req_extensions = v3_req # The extensions to add to a certificate request
[ v3_req ]
#Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
[ alt_names ]
IP.1= 172.16.10.1 # --> 修改后台管理地址,eg. 192.168.1.1
DNS.1 = 172.16.10.1
6、重启uhttpd
root@OpenWrt:~# /etc/init.d/uhttpd restart
4+0 records in
4+0 records out
Generating a RSA private key
.+++++
..................+++++
writing new private key to '/etc/uhttpd.key.new'
-----
如果出现上面的输出信息就说明成功了,重新打开路由器的管理后台 https://172.16.10.1 浏览器选择 高级–信任证书 就可以了。也可以—> https://openwrt.lan
参考
1、https://openwrt.org/zh-cn/doc/uci/uhttpd