作者归档:CD

使用caddy反向代理deluge的webui

20191007更新

最近用下面的老方法遇到了问题,表现为打开coldawn.com/deluge一片空白,chrome错误代码为:

because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. 
net::ERR_ABORTED 404 

经过多次尝试,仍然失败。解决办法使使用二级域名反代deluge,如下:

deluge.coldawn.com {
    proxy / http://127.0.0.1:8112 {
      transparent
      websocket
    }
}

访问deluge.coldawn.com即可。

注意将:deluge.coldawn.com改成你自己的二级域名。

老方法

方法很简单,一行搞定,代码如下:

proxy /deluge http://127.0.0.1:8112/ { transparent without /deluge header_upstream X-Deluge-Base "/deluge" }

然后访问自己的域名+/deluge即可,如:

coldawn.com/deluge

为网站开启QUIC的几点注意事项

QUIC的文章比较多了,但是开启起来仍然是件困扰人的事。本文简要记录一下为网站开启QUIC的几点注意事项。

一 QUIC对比现有HTTP2的主要优势:

  • 显著减少连接建立时间
  • 改进的拥塞控制
  • 无对头阻塞的多路复用
  • 前向纠错
  • 连接迁移

二 开启QUIC的注意事项主要有以下几点:

Caddy的13f9c34已经支持QUIC 44、43、39,运行参数中加入-quic

编译caddy时,需要为主分支的quic-go打一个补丁:
cd $GOPATH/src/github.com/mholt/caddy/vendor/github.com/lucas-clemente/quic-go/

vi quic.patch

quic.pathch的内容如下:

From 20719a7c50c1f97ff0f2272010cda5710794c1d0 Mon Sep 17 00:00:00 2001
From: Marten Seemann <martenseemann@gmail.com>
Date: Thu, 29 Nov 2018 20:33:02 +0700
Subject: [PATCH] use the original tls.Config if tls.Config.GetConfigForClient
 returns nil

---
 internal/crypto/cert_chain.go      | 15 ++++++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/internal/crypto/cert_chain.go b/internal/crypto/cert_chain.go
index 0c728fd25..45af2952d 100644
--- a/internal/crypto/cert_chain.go
+++ b/internal/crypto/cert_chain.go
@@ -56,8 +56,7 @@ func (c *certChain) GetLeafCert(sni string) ([]byte, error) {
 }
 
 func (c *certChain) getCertForSNI(sni string) (*tls.Certificate, error) {
-	conf := c.config
-	conf, err := maybeGetConfigForClient(conf, sni)
+	conf, err := maybeGetConfigForClient(c.config, sni)
 	if err != nil {
 		return nil, err
 	}
@@ -107,7 +106,13 @@ func maybeGetConfigForClient(c *tls.Config, sni string) (*tls.Config, error) {
 	if c.GetConfigForClient == nil {
 		return c, nil
 	}
-	return c.GetConfigForClient(&tls.ClientHelloInfo{
-		ServerName: sni,
-	})
+	confForClient, err := c.GetConfigForClient(&tls.ClientHelloInfo{ServerName: sni})
+	if err != nil {
+		return nil, err
+	}
+	// if GetConfigForClient returns nil, use the original config
+	if confForClient == nil {
+		return c, nil
+	}
+	return confForClient, nil
 }

patch -p1 < quic.patch

之后再进入caddy目录进行下一步的编译:

cd $GOPATH/src/github.com/mholt/caddy

请升级到目前的最新版 1.11。

  • 在防火墙中为443端口开启udp

          Firewalld:

sudo firewall-cmd --zone=public --add-port=443/udp --permanent

          iptables:

sudo iptables -A INPUT -p udp --dport 443 -j ACCEPT
  • 将Chrome升级到最新版

在chrome://flags/#enable-quic中启用QUIC支持。

三 一个查看QUIC支持情况的命令

curl -I https://www.coldawn.com we get
HTTP/1.1 200 OK
Alt-Svc: quic=":443"; ma=2592000; v="44,43,39"
Cache-Control: max-age=8640000
Content-Type: text/html; charset=UTF-8
Link: <https://www.coldawn.com/wp-json/>; rel="https://api.w.org/"
Server: Caddy
Strict-Transport-Security: max-age=31536000;
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Powered-By: PHP/7.2.10
X-Xss-Protection: 1; mode=block
Date: Fri, 28 Sep 2018 04:29:41 GMT

解决CentOS 7 上yum update时出现的Error: Multilib version problems found.

现象描述

CentOS 7.5 系统,sudo yum update,出现如下错误:

Error:  Multilib version problems found. This often means that the root cause is something else and multilib version checking is just pointing out that there is a problem. Eg.:
       
 1. You have an upgrade for audit-libs which is missing some dependency that another package requires. Yum is trying to solve this by installing an older version of audit-libs of the different architecture. If you exclude the bad architecture yum will tell you what the root cause is (which package requires what). You can try redoing the upgrade with --exclude audit-libs.otherarch ... this should give you an error message showing the root cause of the problem.
       
 2. You have multiple architectures of audit-libs installed, but yum can only see an upgrade for one of those architectures.
 If you don't want/need both architectures anymore then you can remove the one with the missing update and everything will work.
       
 3. You have duplicate versions of audit-libs installed already. You can use "yum check" to get yum show these errors. ...you can also use --setopt=protected_multilib=false to remove this checking, however this is almost never the correct thing to do as something else is very likely to go wrong (often causing much more problems).
       
 Protected multilib versions: -2.8.1-3.el7_5.1.i686 != audit-libs-2.8.1-3.el7.x86_64
Error: Protected multilib versions: systemd-libs-219-57.el7_5.1.i686 != systemd-libs-219-57.el7.x86_64

尝试单独更新相关软件包

单独更新audit-libs,失败

sudo yum update audit-libs

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.usc.edu
 * elrepo-kernel: repos.lax-noc.com
 * epel: mirrors.develooper.com
 * extras: mirrors.xtom.com
 * updates: mirror.hostduplex.com
 * webtatic: us-east.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package audit-libs.i686 0:2.8.1-3.el7 will be updated
---> Package audit-libs.x86_64 0:2.8.1-3.el7 will be updated
--> Processing Dependency: audit-libs(x86-64) = 2.8.1-3.el7 for package: audit-libs-python-2.8.1-3.el7.x86_64
--> Processing Dependency: audit-libs(x86-64) = 2.8.1-3.el7 for package: audit-2.8.1-3.el7.x86_64
---> Package audit-libs.i686 0:2.8.1-3.el7_5.1 will be an update
---> Package audit-libs.x86_64 0:2.8.1-3.el7_5.1 will be an update
--> Running transaction check
---> Package audit.x86_64 0:2.8.1-3.el7 will be updated
---> Package audit.x86_64 0:2.8.1-3.el7_5.1 will be an update
---> Package audit-libs-python.x86_64 0:2.8.1-3.el7 will be updated
---> Package audit-libs-python.x86_64 0:2.8.1-3.el7_5.1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved
=======================================================================================================================================================
 Package                                  Arch                          Version                                   Repository                      Size
=======================================================================================================================================================
Updating:
 audit-libs                               i686                          2.8.1-3.el7_5.1                           updates                        100 k
 audit-libs                               x86_64                        2.8.1-3.el7_5.1                           updates                         99 k
Updating for dependencies:
 audit                                    x86_64                        2.8.1-3.el7_5.1                           updates                        247 k
 audit-libs-python                        x86_64                        2.8.1-3.el7_5.1                           updates                         75 k

Transaction Summary
=======================================================================================================================================================
Upgrade  2 Packages (+2 Dependent packages)

Total size: 521 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test


Transaction check error:
  package audit-libs-2.8.1-3.el7_5.1.x86_64 is already installed

Error Summary
-------------

单独更新systemd-libs,失败

sudo yum update systemd-libs

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.usc.edu
 * elrepo-kernel: repos.lax-noc.com
 * epel: mirrors.develooper.com
 * extras: mirrors.xtom.com
 * updates: mirror.hostduplex.com
 * webtatic: us-east.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package systemd-libs.i686 0:219-57.el7 will be updated
--> Processing Dependency: systemd-libs = 219-57.el7 for package: systemd-219-57.el7.x86_64
--> Processing Dependency: systemd-libs = 219-57.el7 for package: libgudev1-219-57.el7.x86_64
---> Package systemd-libs.x86_64 0:219-57.el7 will be updated
--> Processing Dependency: systemd-libs = 219-57.el7 for package: systemd-219-57.el7.x86_64
---> Package systemd-libs.i686 0:219-57.el7_5.1 will be an update
---> Package systemd-libs.x86_64 0:219-57.el7_5.1 will be an update
--> Running transaction check
---> Package libgudev1.x86_64 0:219-57.el7 will be updated
---> Package libgudev1.x86_64 0:219-57.el7_5.1 will be an update
---> Package systemd-libs.i686 0:219-57.el7 will be updated
--> Processing Dependency: systemd-libs = 219-57.el7 for package: systemd-219-57.el7.x86_64
---> Package systemd-libs.x86_64 0:219-57.el7 will be updated
--> Processing Dependency: systemd-libs = 219-57.el7 for package: systemd-219-57.el7.x86_64
--> Finished Dependency Resolution
Error: Package: systemd-219-57.el7.x86_64 (@base)
           Requires: systemd-libs = 219-57.el7
           Removing: systemd-libs-219-57.el7.i686 (@base)
               systemd-libs = 219-57.el7
           Updated By: systemd-libs-219-57.el7_5.1.i686 (updates)
               systemd-libs = 219-57.el7_5.1
 You could try using --skip-broken to work around the problem
** Found 18 pre-existing rpmdb problem(s), 'yum check' output follows:
....

解决办法

系统是64位的,我们在上一步发现了两个不符合x86_64构架的包全名:

audit-libs.i686 0:2.8.1-3.el7

systemd-libs-219-57.el7.i686


需要做的就是移除它们:

sudo yum remove audit-libs.i686 0:2.8.1-3.el7

sudo yum remove systemd-libs-219-57.el7.i686

然后更新系统即可:
sudo yum update

在树莓派3B上安装OpenWrt 18.06.0

更新日志

20180910
OpenWrt 升级至18.06.1;
更正部分疏漏和错误;
有趣的地方在于:直接格式化存储卡,写入 18.06.1镜像,上电,发现之前的设置居然还在。使用firstboot命令后才清除。


经历LEDE分支的快速发展后,OpenWRT与LEDE又重新走到了一起,并于2018年7月放出了首次合并后的正式版OpenWrt 18.06.0。今天介绍下如何在树莓派3 Modle B上安装正式版的OpenWrt 18.06.0,主要目的是介绍如何配置3B的网络。

安装OpenWRT

下载所需的固件和写入软件

下载适配树莓派3B的固件

openwrt-18.06.1-brcm2708-bcm2710-rpi-3-squashfs-factory.img.gz

解压后得到openwrt-18.06.1-brcm2708-bcm2710-rpi-3-squashfs-factory.img。

下载并安装写入软件

Win32DiskImager

写入OpenWRT

建议将TF卡事先格式化一次,保证卡上内容为空。

以管理员方式打开Win32DiskImager,在“Image File”处选择解压好的“openwrt-18.06.1-brcm2708-bcm2710-rpi-3-squashfs-factory.img”,谨慎选择要写入的目标TF卡所在的盘符“Device”,之后点击“Write”写入。

修改OpenWRT网络配置

初始化设置

将写好的TF卡插入3B,通电,以网线连接上3B与电脑,打开 192.168.1.1,直接点击“Login”登陆。

设置密码和修改SSH设置

点击上方提示处的“Go to password configuration…”,
设置密码(Router Password)。
将“Dropbear Instance”下的“Interface”选择“lan”,之后点击“Save & Apply”保存并生效。

开启并连接3B的无线网络

依次打开“Network” > “Wireless”,在“Wireless Overview”界面,找到“SSID: OpenWrt | Mode: Master”,点击“Enable”开启无线,此无线的用户名为“OpenWrt”,默认密码为空。
断开有线连接,在无线网络找到“OpenWrt”,进行连接,重新登陆路由器。

修改网络接口设置并添加WAN口配置

修改LAN接口网卡适配器的设置

依次打开“Network” > “Interfaces”,在”Interfaces”下找到“LAN”,点击“Edit”进入“Interfaces – LAN”的配置界面,找到“Common Configuration”选项卡下的“Physical Settings”,在“Interface”点击右侧的下拉列表,去掉“Ethernet Adapter: “eth0” (lan)”前面的钩,之后点击“Save & Apply”保存并生效。

对无线网络的进一步配置,如更改无线名称,加密设置等在此不赘述。

添加WAN口

依次打开“Network” > “Interfaces”,点击“Add new interface…”打开新建接口的界面“Create Interface”,如下修改:

  • “Name of the new interface”处,填入“WAN”。
  • “Protocol of the new interface”处,根据是否由光猫拨号进行选择:如果是宽带的账户密码在光猫中设置并拨号,就选择“DHCP client”;如果是在树莓派的OpenWRT中设置宽带账号并拨号,就选择“PPPoE”。
  • “Cover the following interface”处,选择“Ethernet Adapter: “eth0″”。

设置好之后,点击“Submit”提交修改。
此时,返回WAN口的设置界面“Interfaces – WAN”:
如果选择了PPPoE,就在该界面下方输入宽带的用户名“PAP/CHAP username
”和密码“PAP/CHAP password”。
在该界面的右侧防火墙设置“Firewall Settings”中:
“Create / Assign firewall-zone”处,选择“wan:(empty)”。
点击“Save & Apply”保存并生效。

安装中文语言包和material主题

putty登陆3B,安装语言包和material主题

opkg update
opkg install luci-theme-material luci-i18n-base-zh-cn

为IOS 1password 启用PIN 码

从安全的角度来说,指纹识别和faceID比密码(PIN)要好,但是对于没有faceID的IOS设备,有不少时候指纹识别不灵敏或者无法识别。这时需要输入较长的1password主密码,这是令人头痛的事。好在IOS版1password提供了PIN码功能,即输入四位数字密码,即可解锁1password。

但是这个功能隐藏的比较深。具体开启方法如下:

登录1password,“设置”-“高级”-“安全”-“PIN码”。

注意:开启PIN码后,将不能使用指纹识别和faceID来登陆1password。

谷歌翻译扩展程序划词翻译无效的问题

现象描述:
Chrome安装Google翻译扩展程序后,在网页中选中要翻译的内容或者双击鼠标左键选中某单词,期待的正常情况是在所选的文字旁边自动弹出翻译的图标,但是事实上是绝大多数时候都不出现,只能右键或者点击工具栏上的翻译图标才能翻译。
解决方法:
依次找到Chrome工具栏右侧“三个竖点” > 设置 > 高级 > 语言 > 语言
将“询问是否翻译非您所用语言的网页”的选项关闭。可能原因是:内置的翻译和Google翻译冲突。

CentOS 7 上使用Certbot申请通配符证书(ACMEv2 Wildcard Certificates)

通配符证书(泛域名证书)对于小博客来说,毫无用处,但是要赶个时髦。本文记录下申请RSA和ECDSA通配符证书的过程。

1 安装Certbot

签署通配符证书需要Certbot 0.22以上。如果以前安装过certbot,一般是直接yum update即可。如果是全新安装,则如下:
先升级:

yum update -y

查看系统版本:

cat  /etc/centos-release CentOS Linux release 7.4.1708 (Core)

安装epel源:

yum install epel-release -y

安装certbot:

yum install certbot -y

查看certbot版本:

certbot --version certbot 0.22.0

2 申请RSA通配符证书的过程

2.1 用如下命令申请证书

co1dawn.com和*.co1dawn.com换成自己的域名;执行该命令时不依赖nginx。

certbot -d co1dawn.com -d *.co1dawn.com --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory certonly --agree-tos

输入应急邮箱,证书到期前会有邮件提示:

Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):

如果想跳过输入邮箱的步骤,可在申请命令后面加上:

--register-unsafely-without-email

之后出现如下提示:要公开记录申请该证书的IP地址,是否同意?不同意就无法继续。

-------------------------------------------------------------------------------
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.

Are you OK with your IP being logged?
-------------------------------------------------------------------------------
(Y)es/(N)o: y

同意之后,出现如下提示,第一个“Press Enter to Continue”处直接回车,第二个“Press Enter to Continue”不要按回车:

-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.co1dawn.com with the following value:

iLS0NjcdP3RR1KphB6xbbVnKS_NS2uMW-xdDRzz85OM

Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue             #此处直接回车

-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.co1dawn.com with the following value:

f3V7aw5GPm5yzNsJFanQQaUFMyVQcqriUe3UjIDUHn0

Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue             #此处不要按回车
2.2 为DNS解析增加TXT记录

进入自己域名的DNS记录管理页面,增加两条TXT记录,多数情况下,仅需在域名(Name)处填入_acme-challenge,在内容(Target)处填入上一步Certbot生成的内容即可,不同DNS提供商处可能会略有不同,根据实际情况修改:

    Name                                     Target
_acme-challenge             iLS0NjcdP3RR1KphB6xbbVnKS_NS2uMW-xdDRzz85OM
_acme-challenge             f3V7aw5GPm5yzNsJFanQQaUFMyVQcqriUe3UjIDUHn0

稍等片刻,等TXT记录解析生效。查看是否生效的命令和生效后的查询结果如下:

host -t txt _acme-challenge.co1dawn.com
_acme-challenge.co1dawn.com descriptive text "iLS0NjcdP3RR1KphB6xbbVnKS_NS2uMW-xdDRzz85OM" 
_acme-challenge.co1dawn.com descriptive text "f3V7aw5GPm5yzNsJFanQQaUFMyVQcqriUe3UjIDUHn0"
2.3 继续申请证书

当第2.2步查看TXT记录解析成功后,回到申请证书的第2.1步处,直接回车,等待:

Waiting for verification...
Resetting dropped connection: acme-v02.api.letsencrypt.org
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/co1dawn.com-0001/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/co1dawn.com-0001/privkey.pem
   Your cert will expire on 2018-06-14. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

这表示已成功生成新的证书和密钥,修改nginx的配置文件定位新证书和密钥的位置后重启nginx即可。

3 申请ECDSA通配符证书

3.1 首先是生成支持通配符证书的请求文件

步骤请参考这篇文章:使用Let’s Encrypt的Certbot为ngxin生成ECDSA证书,以下内容中的文件名基本和这篇文章相同。
生成ECDSA私钥:

openssl ecparam -genkey -name secp384r1 > ec.key

生成通配符证书的请求文件的命令需要改为:

openssl req -new -sha384 -key ec.key -subj "/CN=co1dawn.com" -reqexts SAN -config <(cat /usr/local/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:co1dawn.com,DNS:*.co1dawn.com")) -outform der -out ec-der.csr

ec.key 是自己生成的私钥
co1dawn.com 改成自己的域名
ec-der.csr 支持通配符证书的请求文件,假设放到/usr/local/src下,下面会用到

3.2 申请通配符证书

步骤和申请默认的RSA通配符证书基本一致,而且TXT记录相同,无需再次添加了。

certbot -d co1dawn.com -d *.co1dawn.com --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory certonly --csr "/usr/local/src/ec-der.csr"

之后一路回车即可。

解决编译LEDE时bughost.org无法访问致下载IPW-2100fw/2200fw驱动失败的问题

尝试编译LEDE固件,遇到IPW-2100fw和ipw2200-fw下载失败。
注意到Makefile中相关字段:

cat package/kernel/mac80211/Makefile
...
IPW2100_NAME:=ipw2100-fw
IPW2100_VERSION:=1.3

define Download/ipw2100
  URL:=http://bughost.org/firmware/
  FILE:=$(IPW2100_NAME)-$(IPW2100_VERSION).tgz
  HASH:=e1107c455e48d324a616b47a622593bc8413dcce72026f72731c0b03dae3a7a2
endef
$(eval $(call Download,ipw2100))
...
IPW2200_NAME:=ipw2200-fw
IPW2200_VERSION:=3.1

define Download/ipw2200
  URL:=http://bughost.org/firmware/
  FILE:=$(IPW2200_NAME)-$(IPW2200_VERSION).tgz
  HASH:=c6818c11c18cc030d55ff83f64b2bad8feef485e7742f84f94a61d811a6258bd
endef
$(eval $(call Download,ipw2200))
...

原因是bughost.org最近几天down机了。
解决方法是将Makefile中的bughost.org换成其他的源,按如下修改再编译就可以了。

...
IPW2100_NAME:=ipw2100-fw
IPW2100_VERSION:=1.3

define Download/ipw2100
  URL:=https://people.freebsd.org/~flz/distfiles/ipw/
  FILE:=$(IPW2100_NAME)-$(IPW2100_VERSION).tgz
  HASH:=e1107c455e48d324a616b47a622593bc8413dcce72026f72731c0b03dae3a7a2
endef
$(eval $(call Download,ipw2100))
...
IPW2200_NAME:=ipw2200-fw
IPW2200_VERSION:=3.1

define Download/ipw2200
  URL:=https://people.freebsd.org/~flz/distfiles/ipw/
  FILE:=$(IPW2200_NAME)-$(IPW2200_VERSION).tgz
  HASH:=c6818c11c18cc030d55ff83f64b2bad8feef485e7742f84f94a61d811a6258bd
endef
$(eval $(call Download,ipw2200))
...

CentOS 7 编译安装nginx并启用TLS1.3

暂时转向caddy,caddy已经可以支持tls v1.3

更新日志

20180708
OpenSSL于2018年6月8日更新了关于tls 1.3的说明,见此wiki,本文按新wiki修改更新;
主要变化有:OpenSSL目前同时支持“draft-26”, "draft-27" and "draft-28"草案;简化流程,编译时默认开启tls 1.3,无需enable参数;加密算法表达的更新;
Chrome canary 69.0.3484.0 和 Firefox Nightly 63.0a1支持tls1.3 Draft 28。
20180411
Firefox Nightly 61.0a1支持tls1.3 Draft 26。
20180404
IESG批准将TLS 1.3 Draft 28作为TLS version 1.3 的建议标准;
至20180404,Openssl支持的标准为Draft 26。
20180312
Chrome 65正式版已经发布,支持tls1.3 Draft 23。
20180207
修正部分错误。
如果TLSv1.3如期发布,OpenSSL 1.1.1 将于2018年4月17日面向公众发布。对于服务器来说,我还是喜欢CentOS,支持周期很长,折腾一次可以用很长世间,因此以下记录一下在基于LNMP的CentOS 7 系统上启用TLSv1.3的过程。

1 升级系统

yum update

升级后的系统版本为:

cat /etc/centos-release CentOS Linux release 7.5.1804 (Core)

2 安装官方mainline版的nginx

通过官方源安装nginx的目的是:
自动生成nginx的配置文件,减少大量的工作;
获取nginx的编译参数。

配置源:

vi /etc/yum.repos.d/nginx.repo

写入如下内容:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1

安装nginx:

yum install nginx -y

查看nginx版本:

nginx -v nginx version: nginx/1.15.1

获取编译参数:

nginx -V nginx version: nginx/1.15.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

修改nginx源,将enabled=1改为enabled=0,防止yum update时nginx被更新掉

vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck=0 enabled=0

3 编译nginx

安装可能用到的依赖:

yum install -y git gcc gcc-c clang automake make autoconf libtool zlib-devel libatomic_ops-devel pcre-devel openssl-devel libxml2-devel libxslt-devel gd-devel GeoIP-devel gperftools-devel  perl-devel perl-ExtUtils-Embed

获取源码:

git clone https://github.com/nginx/nginx.git
git clone https://github.com/openssl/openssl.git
git clone https://github.com/grahamedgecombe/nginx-ct.git

nginx-ct是启用证书透明度(Certificate Transparency)策略的模块。为了启用Certificate Transparency和TLSv1.3,需要额外加入如下编译参数:

--add-module=../nginx-ct/ --with-openssl=../openssl/

加在官方编译参数后面,简单修改形成完整的编译参数:

auto/configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=../nginx-ct/ --with-openssl=../openssl/

进入nginx源码目录,并输入如上完整的编译参数。
开始编译:

make

查看编译好的nginx信息:

./objs/nginx -v nginx version: nginx/1.15.2

备份已经安装好的官方mainline版,安装编译版:

mv /usr/sbin/nginx /usr/sbin/nginx.1.15.1.20180708.official.mainline
cp ./objs/nginx /usr/sbin/

4 修改nginx配置文件内的ssl_protocols和ssl_ciphers,默认启用TLSv1.3的前三项常用的加密算法

...
ssl_protocols          TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers            EECDH+CHACHA20:ECDHE+aECDSA+CHACHA20:ECDHE+aRSA+CHACHA20:ECDHE+aECDSA+AESGCM:ECDHE+aRSA+AESGCM:ECDHE+aECDSA+AES256+SHA384:ECDHE+aRSA+AES256+SHA384:ECDHE+aECDSA+AES256+SHA:ECDHE+aRSA+AES256+SHA;
...

重启nginx服务以使修改生效:

systemctl restart nginx

5 测试TLSv1.3是否生效

5.1 使用testssl工具
git clone --depth 1 https://github.com/drwetter/testssl.sh.git
cd testssl.sh
./testssl.sh --help

命令为(coldawn.com需要换成自己的域名):

./testssl.sh -p coldawn.com ... Testing protocols via sockets except SPDY+HTTP2 SSLv2 not offered (OK) SSLv3 not offered (OK) TLS 1 offered TLS 1.1 offered TLS 1.2 offered (OK) TLS 1.3 offered (OK): draft 28, draft 27, draft 26 NPN/SPDY h2, http/1.1 (advertised) ALPN/HTTP2 h2, http/1.1 (offered) ...

详细的情况,用大写的P作为参数:

./testssl.sh -P coldawn.com

 Testing server preferences

 Has server cipher order?     yes (OK)
 Negotiated protocol          TLSv1.3
 Negotiated cipher            TLS_AES_256_GCM_SHA384, 253 bit ECDH (X25519)
 Cipher order
    TLSv1:     ECDHE-RSA-AES256-SHA
    TLSv1.1:   ECDHE-RSA-AES256-SHA
    TLSv1.2:   ECDHE-RSA-CHACHA20-POLY1305 ECDHE-RSA-AES256-GCM-SHA384 ECDHE-RSA-AES128-GCM-SHA256 ECDHE-RSA-AES256-SHA384 ECDHE-RSA-AES256-SHA
    TLSv1.3:   TLS_AES_256_GCM_SHA384 TLS_CHACHA20_POLY1305_SHA256 TLS_AES_128_GCM_SHA256
5.2 使用现代浏览器

Chrome canary 69.0.3484.0 和 Firefox Nightly 63.0a1已经支持tls1.3 Draft 28。

HTML网页中插入经base64编码的中文(Data URLs)的一个方法

Data URLs出现的目的是将经base64编码的小文件直接插入文档中。相对常用的用法是将小图片转换为Data URLs直接嵌入到网页中。
有时候我们在编写网页时写入中文会出现乱码,这时我们想到了Data URLs。比如说,有人问:把base64编码格式的中文显示在HTML中,该怎么做,回答者认为是不可以的。
其实,方法也不是没有。举个例子,我们想在网页中以Data URLs方式写入“中文字符”四个字,其过程是:
1 将“中文字符”四个字利用在线编码工具进行base64编码,编码后为

5Lit5paH5a2X56ym

2 按照示例,添加“前缀”、“类型”后,Data URLs为:

data:text/plain;base64,5Lit5paH5a2X56ym

3 将上述URL复制到Chrome的地址栏进行解码,发现为乱码:

涓枃瀛楃

4 原因是对于text文本,Data URLs默认的编码类型是US-ASCII。所以对于中文文本来说,需要将编码类型注明为UTF-8,Data URLs的正确写法是:

data:text/plain;charset=UTF-8;base64,5Lit5paH5a2X56ym

此时再复制到Chrome地址栏,则会正常显示其内容:

中文字符

5 直接将上述Data URLs数据插入HTML网页中,不会解析为“中文字符”,而是直接显示这串数据。这时需要使用到一个HTML5引入的标签:embed,其包含一个类型type的属性。写法为:

<embed src="data:text/plain;charset=UTF-8;base64,5Lit5paH5a2X56ym" type="text/plain" />

将上述Data URLs数据插入HTML网页中则会正确解析为“中文字符”。

上述方法可以把base64编码格式的中文显示在HTML中,但是其显示样式还需要进一步调整。