【问题标题】:Update nginx in ubuntu 14.04在 ubuntu 14.04 中更新 nginx
【发布时间】:2019-05-22 00:05:02
【问题描述】:

在我的服务器中,nginx -v 返回nginx version: nginx/1.4.6 (Ubuntu),它很旧,所以我决定将它更新到最新的稳定版本。

然后,我关注了this answer

sudo apt-get update
sudo apt-get install nginx

它给出:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  nginx-common nginx-core
Suggested packages:
  fcgiwrap nginx-doc
The following packages will be upgraded:
  nginx nginx-common nginx-core
3 upgraded, 0 newly installed, 0 to remove and 311 not upgraded.
Need to get 349 kB of archives.
After this operation, 3,072 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 http://mirrors.digitalocean.com/ubuntu/ trusty-updates/main nginx-common all 1.4.6-1ubuntu3.7 [19.0 kB]
Get:2 http://mirrors.digitalocean.com/ubuntu/ trusty-updates/main nginx all 1.4.6-1ubuntu3.7 [5,352 B]
Get:3 http://mirrors.digitalocean.com/ubuntu/ trusty-updates/main nginx-core amd64 1.4.6-1ubuntu3.7 [325 kB]
Fetched 349 kB in 0s (431 kB/s)
Preconfiguring packages ...
(Reading database ... 111751 files and directories currently installed.)
Preparing to unpack .../nginx-common_1.4.6-1ubuntu3.7_all.deb ...
Unpacking nginx-common (1.4.6-1ubuntu3.7) over (1.4.6-1ubuntu3.5) ...
Preparing to unpack .../nginx_1.4.6-1ubuntu3.7_all.deb ...
Unpacking nginx (1.4.6-1ubuntu3.7) over (1.4.6-1ubuntu3.5) ...
Preparing to unpack .../nginx-core_1.4.6-1ubuntu3.7_amd64.deb ...
Unpacking nginx-core (1.4.6-1ubuntu3.7) over (1.4.6-1ubuntu3.5) ...
Processing triggers for ufw (0.34~rc-0ubuntu2) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up nginx-common (1.4.6-1ubuntu3.7) ...
Setting up nginx-core (1.4.6-1ubuntu3.7) ...
Setting up nginx (1.4.6-1ubuntu3.7) ...

但是,nginx -v 仍然返回 nginx version: nginx/1.4.6 (Ubuntu)

有谁知道在不修改配置文件的情况下更新 nginx 的安全方法?因为是在生产中的服务器上,所以要非常小心...

【问题讨论】:

  • 为什么要更新到较新的版本?您有新版本解决的具体问题吗?
  • 不,我没有具体的原因……升级 nginx 有那么可怕吗?
  • 您是否检查过您当前的配置是否与最新版本兼容?您是否要花时间确保最新版本与当前版本的工作方式相同?您可以承受多长时间的生产服务器停机时间? Nginx 的升级并没有那么可怕,但总是有可能发生细微的行为变化,这将完全破坏您的生产,并且需要数小时才能进行调试。尤其是当您同时跳转多个版本时。
  • 升级前有没有办法检查当前配置是否兼容最新版本?
  • 良好的做法是拥有镜像生产的暂存环境来测试此类更改。或者,您可以使用与生产环境相同的环境设置临时 VM。

标签: ubuntu nginx digital-ocean


【解决方案1】:

首先,运行

sudo apt-get install software-properties-common python-software-properties

然后,添加 nginx stable repo:

sudo add-apt-repository ppa:nginx/stable

然后运行

sudo apt-get 更新

sudo apt-get install nginx

【讨论】:

  • 这对我有用,谢谢。我认为备份以前的 nginx 文件夹可能是个好主意,以防万一。例如。作者:cp -r /etc/nginx /etc/nginx-bkp
  • 要获取add-apt-repository 命令,请使用sudo apt-get install software-properties-common python-software-properties
【解决方案2】:

2019年更新:可使用ppa解决方案将Nginx升级到1.14.x。为了将 Nginx 升级到最新的稳定版或主线版本,您需要先卸载 Nginx,然后按照document 重新安装:

// Uninstall Nginx
sudo apt-get remove nginx

//Then, install Nginx following document: http://nginx.org/en/linux_packages.html#Ubuntu
sudo apt install curl gnupg2 ca-certificates lsb-release
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx"| sudo tee /etc/apt/sources.list.d/nginx.list
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
sudo apt update
sudo apt install nginx

【讨论】:

  • 为我工作:nginx 版本:nginx/1.4.6 (Ubuntu),由 gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1) 构建
【解决方案3】:

最新的 Ubuntu 14.04 带有 nginx-1.4.6,将你的 nginx 升级到最新的稳定版本是个好主意。升级的一个正当理由可能是支持http/2,它在nginx - 1.9.5 之后正式可用

在此处发布答案以获得更安全的升级,以便将来可以帮助某人。

最推荐的安装 nginx 的方法是使用它的 ppa。如果可能,在安装新的之前停止 nginx。此外,备份您可能完成的任何配置总是一个好主意。最佳案例备份/etc/nginx 安全的地方。但是,您需要的最重要的备份文件是 nginx.conf,它肯定会被新配置覆盖。也不要忘记添加 nginx 签名密钥。更多信息here

cd /tmp
sudo add-apt-repository ppa:nginx/stable
wget sudo add-apt-repository ppa:nginx/stable
sudo apt-key add nginx_signing.key
rm nginx_signing.key
sudo apt-get update
sudo cp -r /etc/nginx nginx-bkp
sudo service stop nginx 
sudo apt-get install nginx

升级 nginx 时,它会问你以下问题。首先确保您已备份nginx.conf,然后回答Y。我首先想检查与D 的区别,然后使用Y

在我的例子中,我在 nginx.conf 中定义了自定义日志格式,因为升级后 nginx 无法启动。我所要做的就是打开/etc/nginx/nginx.conf 并提供我的自定义日志格式以使一切恢复正常。

之后检查你的 nginx 版本并启动它

> sudo nginx -v 
nginx version: nginx/1.12.2
> sudo service nginx start

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-12
    • 1970-01-01
    • 2016-09-29
    • 2015-11-16
    • 1970-01-01
    • 2014-06-11
    • 2016-06-17
    • 1970-01-01
    相关资源
    最近更新 更多