nginx安装-----升级
首先安装低版本:
1、采用编译安装,官网下载好tar包,我采用的1.9和1.12两个,先安装1.9 下载地址:http://nginx.org/en/download.html
上传服务器后解压:
[root@r1 ]# tar -zxvf nginx-1.9.5.tar.gz
进入解压后的目录准备安装:
安装依赖包:
[root@r1 nginx-1.9.5]# yum install -y pcre pcre-devel openssl-devel gcc gcc-c++ autoconf automake make
初学者可以不安装依赖,然后一步步根据报错,缺什么、再去装什么,加深印象!然后总结错误!
[root@r1 nginx-1.9.5]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module --with-stream
./configure 安装前检查所需条件是否具备,通过后根据所加的参数生成Makefile文件;参数就是后面这些选项--prefix=/usr/local/nginx:指定家目录,即使不写默认也是这个。--with-http_ssl_module:添加ssl模块,使用证书HTTPS。--with-http_sub_module:反向代理字符替换模块。--with-stream 四层代理模块tcp协议代理。 还有很多模块和选择,具体可以去官网查看选择:http://nginx.org/en/docs/configure.html

安装:
[root@r1 nginx-1.9.5]# make && make install
make:根据生成的Makefile文件进行编译
make install:根据Makefile文件进行安装和生成配置文件

安装完成后:1、加入开机自启 2、把nginx命令加入全局
1、加开机自启:在rc.local文件中追加 安装目录sbin下的nginx
[root@r1 ~]# echo "/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf">>/etc/rc.local
2、nginx命令加入环境变量或使用软连接
[root@r1 ~]# ln -s /usr/bin/nginx /usr/local/nginx/sbin/nginx
或者:
[root@r1 ~]# vim /etc/profile
export PATH=$PATH:/usr/local/nginx/sbin
保存后执行:
[root@r1 ~]# source /etc/profile
升级nginx
1、解压新版本的nginx-1.12 2、查看原来nginx安装参数 3、最好提前备份好配置文件

2、上图可以看出,我目前版本是之前装的1.9,参数也是上面加的三个,接下来同样的方式,执行./confgure和make
[root@r1 nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_sub_module
在1.12目录中检查安装环境,并带上原有参数,检测完成后备份下原来的nginx脚本
[root@r1 nginx-1.12.2]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old #先备份改名叫old
[root@r1 nginx-1.12.2]# make #开始编译---不执行makeinstall
[root@r1 nginx-1.12.2]# mv objs/nginx /usr/local/nginx/sbin/nginx #编译完成,拷贝1.12目录中objs目录下的nginx到原sbin目录下
以上完成升级

网友评论