编程技术分享平台

网站首页 > 技术教程 正文

在Ubuntu上将Nginx升级到最新版本

xnh888 2024-10-16 17:28:09 技术教程 15 ℃ 0 评论

在Ubuntu上将Nginx升级到最新版本

如果你在Ubuntu上运行nginx,你很快就会发现,操作系统中默认的Ubuntu版本真的很旧。

这意味着你需要运行最新版本的Nginx来避免安全问题。这篇文章是关于如何做到这一点。

第一件事是找出你使用的是哪个版本。以下是你如何做。

$ nginx -v

它应该向你显示类似的内容。

nginx version: nginx/1.10.3 (Ubuntu)

现在我们知道我们需要升级,首先要做的是备份你的配置。

$ sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.1.10.3.backup

安装依赖的东西

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

添加稳定版的Nginx的存储库

$ sudo add-apt-repository ppa:nginx/stable

现在更新它

$ sudo apt-get update

运行安装

$ sudo apt-get install nginx

当它问你是否要继续使用旧的配置或像这样获得新的配置。

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] ?
  

选择N(No)。它将在/etc/nginx/sites-available目录下安装当前配置文件的新版本。

选择Y(es)并获得最新的配置。它将删除当前的配置文件。

再次检查nginx版本。

$ nginx -v

它应该这样说。

nginx version: nginx/1.14.1

现在你的服务器上已经运行了最新版本的Nginx。

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表