截至目前,Debian 9(stretch)安装了易受CVE-2017-7529攻击的nginx 1.10.3版本:
从0.5.6到1.13.2之间的Nginx版本容易受到nginx范围filter模块中的整数溢出漏洞的攻击,导致由特制请求触发的潜在敏感信息的泄漏。
我担心用户数据的安全性,所以我想升级到不再受此问题影响的最新版本。
有多种方法可以获得nginx 1.13.3及以上版本。 你可以自己编译它,使用stretch-backports存储库,或者你可以添加nginx自己的apt库。 在这个答案中,我将会穿过最后一个,因为它可能是三个中最简单的一个。
nginx的网站上有一个关于如何设置他们的存储库的专门页面 ,但是还有更多,特别是如果你想要避免这个特定的漏洞。 stable分支将安装1.12.0,这仍然是脆弱的(它被修补在1.12.1+和1.13.3+),所以你将需要使用mainline ,将安装1.13.5。
在最好的情况下,切换nginx版本应该像运行一些命令一样简单,你将在2-3分钟内完成,停机时间最短。 为了能够尽快恢复正常运行,我们先来准备安装。 首先,您需要将存储库添加到aptconfiguration中,添加签名密钥并更新软件包列表( apt和apt-get在这里工作, apt只是更短)
$ sudo echo "deb http://nginx.org/packages/mainline/debian/ stretch nginx deb-src http://nginx.org/packages/mainline/debian/ stretch nginx" > /etc/apt/sources.list.d/nginx.list $ wget -qO - http://nginx.org/keys/nginx_signing.key | sudo apt-key add - $ sudo apt update
接下来,运行以下命令:
$ sudo apt remove nginx-common
这将有效地从系统中卸载nginx,但将保留您的configuration文件,保存为一个systemd服务文件,这是易于恢复。
接下来从新存储库安装nginx:
$ sudo apt install nginx
请注意,这将询问您是否要replace某些configuration文件,如下所示:
Configuration file '/etc/nginx/nginx.conf' ==> Modified (by you or by a script) since installation. ==> Package distributor has shipped an updated version. What would you like to do about it ? Your options are: Y or I : install the package maintainer's version N or O : keep your currently-installed version D : show the differences between the versions Z : start a shell to examine the situation The default action is to keep your current version. *** nginx.conf (Y/I/N/O/D/Z) [default=N] ?
确保不要inputY ,只要按Enter键或每次inputN都inputN以避免丢失当前的configuration。
如果你不小心覆盖了你的nginx.conf文件,至less需要把文件的最后一行从include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; 恢复以前的包容行为。
您可以validation新安装的版本:
$ nginx -v nginx version: nginx/1.13.5
最后,你会注意到试图运行service nginx start现在失败,并显示以下消息:
Failed to start nginx.service: Unit nginx.service is masked.
这是因为删除nginx-common也会抹掉/lib/systemd/system/nginx.service以前由systemd用来pipe理nginx。 要恢复这个文件,只需使用下面的命令创build它:
$ echo "[Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target " > /lib/systemd/system/nginx.service
最后,运行systemctl unmask nginx然后systemctl enable nginx ,现在你应该可以像以前一样pipe理服务了,以前的所有设置都是完好无损的。
$ service nginx start