適用范圍
本方法適用于使用OpenWrt 在沒有80\443端口、不能dns驗(yàn)證的情況下為自己的域名申請(qǐng)免費(fèi)ssl證書。
提示:
1、如果你的網(wǎng)絡(luò)的80或者443端口是開放狀態(tài),可直接使用https://letsencrypt.org/進(jìn)行ssl申請(qǐng),使用acme.sh腳本可快速完成。
2、如果你的網(wǎng)絡(luò)ddns服務(wù)提供商服務(wù)到位,可以使用dns驗(yàn)證的方法,也更加方便。
本流程適用于上述兩種方法都失效的情況下,采用郵箱驗(yàn)證來完成域名所屬驗(yàn)證。
OpenWrt 分支: 22.03.3 內(nèi)核: 5.10.161
流程簡述
- 在https://zerossl.com/ 上為自己的域名開始申請(qǐng)ssl證書
- 驗(yàn)證的時(shí)候選擇郵箱驗(yàn)證
- 通過在openwrt上架設(shè)郵箱服務(wù)器,完成郵箱驗(yàn)證
- 下載申請(qǐng)到的證書,上傳到openwrt上
- 完成
詳細(xì)流程
在zerossl上申請(qǐng)證書
在申請(qǐng)的時(shí)候需要驗(yàn)證自己域名的所有權(quán),選擇郵箱驗(yàn)證(幸好zerossl支持這種方式)
在openwrt上架設(shè)郵箱服務(wù)器
zerossl是通過發(fā)送郵件到包含域名的郵箱地址的,如 admin@你的域名,所以必須在openwrt上架設(shè)郵箱服務(wù)器。
postfix
使用postfix作為架設(shè)郵箱服務(wù)器的工具,可以通過命令行或者luci安裝 postfix,我這里安裝的版本是3.5.8-2。
安裝完成之后使用vim /etc/postfix/main.cf
編輯配置文件,將下列配置替換域名直接粘貼到最后區(qū)域,覆蓋之前的內(nèi)容。
inet_interfaces = all
inet_protocols = all
default_database_type = cdb
config_directory = /etc/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
shlib_directory = /usr/lib/postfix
manpage_directory = no
data_directory = /usr/var/lib/postfix
queue_directory = /usr/var/spool/postfix
mail_spool_directory = /usr/var/mail
myhostname = 你的域名
mynetworks_style = subnet
經(jīng)過測試這塊代碼這樣是可以運(yùn)行的,如果比較懂的可以自行調(diào)整。
- 可以先檢查配置文件是否有問題:
[root@OpenWrt:10:56 PM /] # /etc/init.d/postfix postinst
postfix: warning: smtputf8_enable is true, but EAI support is not compiled in
postfix: warning: smtputf8_enable is true, but EAI support is not compiled in
postfix: warning: smtputf8_enable is true, but EAI support is not compiled in
newaliases: warning: smtputf8_enable is true, but EAI support is not compiled in
postalias: warning: smtputf8_enable is true, but EAI support is not compiled in
postmap: warning: smtputf8_enable is true, but EAI support is not compiled in
postfix: warning: smtputf8_enable is true, but EAI support is not compiled in
postsuper: warning: smtputf8_enable is true, but EAI support is not compiled i
我這里有這樣的warning,不影響功能。
- 運(yùn)行:
[root@OpenWrt:10:56 PM /] # /etc/init.d/postfix restart
服務(wù)器運(yùn)行成功,不要忘了調(diào)整防火墻設(shè)置,以免郵件發(fā)送不進(jìn)來。
- 測試是否搭建成功
使用google mail發(fā)送任意郵件到root@你的域名測試是否能發(fā)送郵件到我們的服務(wù)器上,這里不要使用qq郵箱,我這里用qq郵箱發(fā)送不進(jìn)來。 - 檢查郵件
稍等一分鐘的樣子,通過如下命令行檢查
這時(shí)應(yīng)該能在其中看到google成功發(fā)送過來的郵件,如果沒有,考慮是否哪里設(shè)置有問題,如ddns解析、防火墻設(shè)置、或者郵箱服務(wù)器設(shè)置是否正確。如果一切正常,郵箱服務(wù)器架設(shè)成功。vim /usr/var/mail/root
創(chuàng)建合適的郵箱賬戶
zerossl上只能選擇固定的幾種郵箱地址來驗(yàn)證,所以root賬戶是不行的,我選擇的是admin@你的域名來驗(yàn)證。這時(shí)候可以通過在openwrt上安裝shadow-useradd來添加用戶,安裝完成之后:
運(yùn)行:
useradd admin
passwd admin
完成之后,重啟postfix:/etc/init.d/postfix restart
zerossl域名驗(yàn)證
選擇admin@你的域名來進(jìn)行驗(yàn)證,這時(shí)候zerossl會(huì)發(fā)送一個(gè)郵件到這個(gè)地址。
使用vim /usr/var/mail/root
來查看郵件內(nèi)容,按照提示完成驗(yàn)證,然后下載證書文件。文章來源:http://www.zghlxwxcb.cn/news/detail-443489.html
上傳證書
- 提前在luci中安裝好luci-app-uhttpd。
- 解壓上一步下載好的證書文件,使用工具將其中的certificate.crt和private.key上傳到openwrt的/etc/目錄。
- 在luci中服務(wù)-uHTTPd中選擇上一步上傳的文件,如下
- 嘗試訪問https接口,看證書是否有效,完成。
參考鏈接:
http://cn.linux.vbird.org/linux_server/0380mail.php#postfix
https://letsencrypt.org/zh-cn/docs/allow-port-80/文章來源地址http://www.zghlxwxcb.cn/news/detail-443489.html
到了這里,關(guān)于OpenWrt 在沒有80\443端口、不能dns驗(yàn)證的情況下為自己的域名申請(qǐng)免費(fèi)ssl證書的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!