ubuntu nginx 升级 ubuntu18有必要升级到20吗
大家好,如果您还对ubuntu nginx 升级不太了解,没有关系,今天就由本站为大家分享ubuntu nginx 升级的知识,包括ubuntu18有必要升级到20吗的问题都会给大家分析到,还望可以解决大家的问题,下面我们就开始吧!
【Linux】Ubuntu安装Nginx(在线安装&源码编译安装)
在Ubuntu 20.04环境中,有两种常见的Nginx安装方式,分别是在线安装和源码编译安装,版本为1.18.0。以下是对这两种方法的详细步骤:
首先,对于在线安装(apt安装):
1.检查当前版本并了解安装详情,可以看到它会自动设置一些路径,比如--prefix和--conf-path,并预装常用的https模块,如--with-http_ssl_module。
其次,如果之前已经通过apt安装了Nginx,源码编译安装前需要卸载并清除相关配置:
1.使用--purge卸载,确保完全移除,但要注意,sudo apt autoremove可能导致未预期的错误。
2.需要手动删除相关依赖。
源码编译安装则包括以下步骤:
2.2.1从nginx官网下载源码。
2.2.2安装过程中,首先解压缩文件,接着配置编译选项,可能会提示缺少pcre和zlib模块。
3.安装这些依赖。
4.开始编译并安装Nginx。
5.启动Nginx后,通过nginx-V检查,由于是自定义编译,可能不会显示所有预装模块。
6.查看安装后的模块,需要在编译目录中查找,通常比apt安装的模块更多。
总的来说,apt安装方式更便捷,而源码编译安装则提供更大的灵活性,可以根据实际需求定制安装。
如何升级Nginx到最新稳定版
如何升级Nginx到最新稳定版
我的环境:
Ubuntu 12.04 LTS
Nginx 1.1.9
Nginx是通过apt-get的方式安装的,所以我的路径与下载代码再编译、安装的有些不一样,我的升级过程如下
1.进入Downloads文件夹
cd/Downloads
2.下载nginx-1.2.5.tar.gz文件到Downloads文件夹中
wget
3.解压nginx-1.2.5.tar.gz文件
tar zxvf nginx-1.2.5.tar.gz
4.进入ngixn-1.2.5文件夹中
cd nginx-1.2.5
5.查看nginx原来的配置
nginx-V
上面的命令将输出:
--prefix=/etc/nginx--conf-path=/etc/nginx/nginx.conf--error-log-path=/var/log/nginx/error.log--http-client-body-temp-path=/var/lib/nginx/body--http-fastcgi-temp-path=/var/lib/nginx/fastcgi--http-log-path=/var/log/nginx/access.log--http-proxy-temp-path=/var/lib/nginx/proxy--http-scgi-temp-path=/var/lib/nginx/scgi--http-uwsgi-temp-path=/var/lib/nginx/uwsgi--lock-path=/var/lock/nginx.lock--pid-path=/var/run/nginx.pid--with-debug--with-http_addition_module--with-http_dav_module--with-http_geoip_module--with-http_gzip_static_module--with-http_image_filter_module--with-http_realip_module--with-http_stub_status_module--with-http_ssl_module--with-http_sub_module--with-http_xslt_module--with-ipv6--with-sha1=/usr/include/openssl--with-md5=/usr/include/openssl--with-mail--with-mail_ssl_module
6.执行configure命令,后面跟上原来nginx的配置
./configure--prefix=/etc/nginx--conf-path=/etc/nginx/nginx.conf--error-log-path=/var/log/nginx/error.log--http-client-body-temp-path=/var/lib/nginx/body--http-fastcgi-temp-path=/var/lib/nginx/fastcgi--http-log-path=/var/log/nginx/access.log--http-proxy-temp-path=/var/lib/nginx/proxy--http-scgi-temp-path=/var/lib/nginx/scgi--http-uwsgi-temp-path=/var/lib/nginx/uwsgi--lock-path=/var/lock/nginx.lock--pid-path=/var/run/nginx.pid--with-debug--with-http_addition_module--with-http_dav_module--with-http_geoip_module--with-http_gzip_static_module--with-http_image_filter_module--with-http_realip_module--with-http_stub_status_module--with-http_ssl_module--with-http_sub_module--with-http_xslt_module--with-ipv6--with-sha1=/usr/include/openssl--with-md5=/usr/include/openssl--with-mail--with-mail_ssl_module
在执行configure时得到几个错误:
a.配置--with-http_xslt_module时提示 the HTTP XSLT module requires the libxml2/libxslt libraries
sudo apt-get install libxml2 libxml2-dev libxslt-dev
b.配置--with-http_image_filter_module时提示 the HTTP image filter module requires the GD library.
sudo apt-get install libgd2-xpm libgd2-xpm-dev
c.配置--with-http_geoip_module时提示 the GeoIP module requires the GeoIP library.
sudo apt-get install geoip-database libgeoip-dev
d.rewrite需要pcre支持,错误提示:./configure: error: the HTTP rewrite module requires the PCRE library.
apt-get install libpcre3 libpcre3-dev
7.再执行第6步的configure命令
8.这次没有提示缺少library,执行make令命编译nginx,编译好以后objs目录下多出一个nginx文件,这个就是已编辑好的nginx程序
make
9.更改旧的nginx程序的名子,并复制新的程序过去,我的旧nginx程序放在/usr/sbin/目录中
mv/usr/sbin/nginx/usr/sbin/nginx-20121122
cp objs/nginx/usr/sbin/nginx
/usr/sbin/nginx-t
执行/usr/sbin/nginx-t命令检查配置文件并将返回下面的信息:
nginx: the configuration file/etc/nginx/nginx.conf syntax is ok
nginx: configuration file/etc/nginx/nginx.conf test is successful
10.在nginx-1.2.5目录下执行下面的命令来升级nginx
make upgrade
11.执行make upgrade得到一个错误:
make:/etc/nginx/sbin/nginx: Command not found
make:*** [upgrade] Error 127
12.用文本编辑器打开修改nginx-1.2.5目录下名为Makefile的文件,将upgrade节点中的/etc/nginx/sbin/nginx改为/usr/sbin/nginx-t,保存后关闭并重新执行make upgrade命令
13.执行nginx-v命令,程序的版本号已经是1.2.5,升级完毕.
ubuntu下升级nginx
在Ubuntu下升级Nginx的步骤如下:
首先,从nginx.org下载稳定版Nginx,如1.6.2版本。
进入文件保存目录,例如/home。
使用wget命令下载Nginx安装包,如wget 。
解压文件,执行tar命令:tar-zxvf nginx-1.6.2.tar.gz。
使用nginx-V查看当前Nginx参数,例如:nginx-V。
进入解压的文件夹,如cd/home/nginx-1.6.2。
执行configure命令,后面跟上相应的参数,例如:./configure--prefix=/usr/share/nginx--conf-path=/etc/nginx/nginx.conf--http-log-path=/var/log/nginx/access.log--error-log-path=/var/log/nginx/error.log--lock-path=/var/lock/nginx.lock--pid-path=/run/nginx.pid--http-client-body-temp-path=/var/lib/nginx/body--http-fastcgi-temp-path=/var/lib/nginx/fastcgi--http-proxy-temp-path=/var/lib/nginx/proxy--http-scgi-temp-path=/var/lib/nginx/scgi--http-uwsgi-temp-path=/var/lib/nginx/uwsgi--with-debug--with-pcre-jit--with-ipv6--with-http_ssl_module--with-http_stub_status_module--with-http_realip_module--with-http_addition_module--with-http_dav_module--with-http_geoip_module--with-http_gzip_static_module--with-http_image_filter_module--with-http_spdy_module--with-http_sub_module--with-http_xslt_module--with-mail--with-mail_ssl_module。
执行命令后,可能会遇到一些问题,如缺少libxslt、GD library、pcre支持、openssl、GeoIP library等。解决方法是使用apt-get安装相应的依赖包。
安装完毕后,执行make命令编译Nginx,然后使用which nginx命令检查Nginx启动程序的位置。
备份旧版本的Nginx可执行文件,使用mv命令将旧文件移动到其他目录,如/usr/sbin/nginx.old。
复制新版本的Nginx可执行文件,使用cp命令将objs目录下的nginx文件复制到/usr/sbin目录下。
检查新版本的Nginx是否正确安装,使用nginx-t命令进行语法检查,确保配置文件无误。
执行make upgrade命令升级Nginx,确保配置正确,无误后运行命令kill-USR2 `cat/usr/local/nginx/logs/nginx.pid`重启Nginx服务。
至此,Nginx升级完成,使用nginx-v命令检查版本号,确保已经升级到指定版本。