背景 Ubuntu最新版也只是将Nginx的支持到了1.18.0,并且爆出了很多漏洞,所以决定将现有的1.18.0停用,改用官网最新的1.25.1版本, 问题是原来的设置不想重新在设置一次。组件不想缺失,最好的办法就是升级。
Nginx的下载 方式 地址为 https://nginx.org/download/nginx-1.25.1.tar.gz
相关依赖包的下载 因为不是Ubuntu根据apt的安装方法,所以事先之前需要下载相应的依赖包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 apt-get install gcc apt-get install libpcre3 libpcre3-dev apt-get install zlib1g zlib1g-dev sudo apt-get install openssl sudo apt-get install libssl-dev sudo apt-get install libgd-dev sudo apt-get install libxml2-dev libxslt1-dev sudo apt-get install libextutils-embed-perl sudo apt-get install libgoogle-perftools-dev sudo yum install pcre pcre-devel sudo yum install openssl openssl-devel sudo yum install libxml2 libxml2-devel libxslt libxslt-devel sudo yum install gd gd-devel sudo yum install perl-ExtUtils-Embed sudo yum install google-perftools google-perftools-devel
解压缩及设置升级 下载好后使用一下命令解压缩nginx-1.25.1.tar.gz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 tar -xvf nginx-1.25.1.tar.gz cd nginx-1.25.1.tarsudo /usr/sbin/nginx -V sudo ./configure --prefix=/usr/local/nginx --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-H4cN7P/nginx-1.21.4=. -fstack-protector-strong....... ' sudo make sudo mv /usr/sbin/nginx /home/username/BK/nginx1.18.0 sudo cp objs/nginx /usr/sbin/nginx sudo /usr/sbin/nginx -t make upgrade sudo /usr/sbin/nginx -V
Nginx的命令 1 2 3 4 5 6 7 8 9 10 nginx nginx -s stop nginx -s quit nginx -s reload nginx -h 显示帮助 nginx -v 显示版本 nginx -V 显示版本,Build, 参数 nginx -t 测试配置 nginx -T 测试并将验证的结果打印在屏幕上
后续问题
错误1:error: the HTTP rewrite module requires the PCRE library
1 2 3 4 5 6 7 8 9 10 sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install openssl libssl-dev sudo yum install pcre pcre-devel
错误2:error: the HTTP gzip module requires the zlib library.
错误3:error: the HTTP XSLT module requires the libxml2/libxslt libraries.
1 2 3 4 5 6 7 8 9 10 11 sudo apt-get update sudo apt-get install libxslt-dev sudo apt-get install libgd-dev sudo apt-get install libgeoip-dev sudo yum install libxml2 libxml2-devel libxslt libxslt-devel
错误4:error: the HTTP image filter module requires the GD library.
1 2 3 4 5 6 7 8 sudo apt-get update sudo apt-get install -y libgd-dev deb http://security.ubuntu.com/ubuntu trusty-security main
在升级Nginx1.18.0至1.22.0版本时执行 sudo apt-get install -y libgd-dev 这个命令时遇到了报错, 报错信息:
1 2 3 4 5 The following packages have unmet dependencies: libgd-dev : Depends: libxpm-dev but it is not going to be installed Depends: libx11-dev but it is not going to be installed Depends: libxt-dev but it is not going to be installed E: Unable to correct problems, you have held broken packages.
执行 sudo apt-get install libxpm-dev libx11-dev libxt-dev 以安装缺少包,又遇到了新的报错,报错信息如下:
1 libx11-dev : Depends: libx11-6 (= 2:1.6.9-2ubuntu1.2) but 2:1.6.9-2ubuntu1.3 is to be installed
通过指定版本来解决
1 2 3 4 5 sudo apt-get install libx11-6=2:1.6.9-2ubuntu1.2 ```bash sudo apt-get install libxpm-dev libx11-dev libxt-dev
1 2 sudo yum install gd gd-devel
错误./configure: error: SSL modules require the OpenSSL library.
需要安装OpenSSL的库 就算你已经安装了OpenSSL也无法整成验证通过, 首先到OpenSSL官网下载最新版本OpenSSL,解压并使用--with-openssl=/PATH/openssl-version
添加到./configure的后面
错误./configure: error: perl module ExtUtils::Embed is required
1 2 3 4 5 sudo apt-get install libextutils-embed-perl sudo yum install perl-ExtUtils-Embed