【Nginx】源码安装Nginx 平滑升级Nginx

Web服务对比

Linux平台

Php、Python:nginx、tengine(淘宝)、apache

Jave:tomcat、Jboss、IBM WebSphere

Windows平台:IIS(.net)

Nginx的优点:性能高、并发高、静态网站、动态网站(php、python)

在对比其他web软件的情况下nginx的性能更加好!在国内广泛使用

Nginx

  • 十分轻量级的HTTP服务器

  • 是一个高性能的HTTP和反向代理服务器
  • 官方网站: http://nginx.org/

Nginx以及现代化软件设计:模块化设计,每个模块实现的功能不一样,并且每个模块都是相互独立的,为了满足不同场景的需求来安装不同的模块.

Nginx分为标准模块(官方)以及第三方开发模块,标准模块有几十个,在安装Nginx时,默认不加模块

在源码编译安装时可使用 ./configure --help来查看nginx标准模块

Nginx标准模块

--with-http_ssl_module    开启SSL加密功能,开启HTTPS(要想启用模块系统环境必须安装openssl-devel依赖包)

--with-stream    TCP/IP调度器模块

--with-http_stub_status_module    查看nginx服务器状态模块

源码安装Nginx

安装依赖包

# yum -y install gcc pcre-devel openssl-devel zlib-devel
gcc:用于C/C++语言的编译
pcre-devel:兼容正则表达式,nginx需要用到正则,比如地址重写
openssl-devel:主要用于加密网站https
zlib-devel:对http包的内容做gzip格式的压缩

创建nginx用户,使用nginx用户来运行nginx主要目的为了安全,不是必须操作

#useradd -s /sbin/nolgin nginx

安装Nginx

#tar -xf nginx-1.10.3.tar.gz    #解压nginx源码包
#cd nginx-1.10.3    #进入nginx1.10.3目录
#./configure --user=nginx --group=nginx --with-http_ssl_module    #检查系统环境,指定安装用户及用户组,安装http_ssl模块
#make  && make install    编译并安装
#ls /usr/local/nginx/     安装完毕后查看安装目录

Nginx目录结构

如果在源码安装时没有选择安装目录,默认安装在/usr/local/nginx下

/usr/local/nginx    主目录
/usr/local/nginx/sbin    主程序
/usr/local/nginx/conf    配置文件
/usr/local/nginx/logs    日志
/usr/local/nginx/html    网页目录

Nginx命令用法

/usr/local/nginx/sbin/nginx    启动服务
/usr/local/nginx/sbin/nginx -s stop    关闭服务
/usr/local/nginx/sbin/nginx -s reloac    重新加载配置文件,在不重启服务的情况下重新加载(不能在关闭服务的时候操作)
/usr/local/nginx/sbin/nginx -V    查看软件信息(能看到怎么安装的configure arguments: --user=nginx --group=nginx --with-http_ssl_module)

当然可以做个软连接放到PATH路径下,方便在命令行执行!ln -s /usr/local/nginx/sbin/nginx /sbin

验证Nginx状态

验证Nginx需要通过监听以及服务来查看,systemctl不能查看

ps -ef | grep nginx
netstat -anptu | grep 80
ss -anptu | grep nginx
curl http://192.168.20.5    #访问nginx


平滑升级Nginx

任何升级都是由风险的!升级前一定要备份!

升级主要是把 /usr/local/nginx/sbin/nginx 这个主程序给替换掉,其他的配置文件、网页目录、日志目录都不需要操作;

升级步骤

1、检查Nginx版本,并备份主程序

# nginx -V
nginx version: nginx/1.10.3    #nginx版本时1.10.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --with-http_ssl_module
# mv /usr/local/nginx/sbin/nginx  /usr/local/nginx/sbin/nginx_1.10.3    #备份主程序

2、解压新版本nginx,并cd到目录下

#tar -xf nginx-1.12.2.tar.gz
#cd nginx-1.12.2/

3、和安装步骤一致,./config 必须和安装时候的操作一样,如果不知道可使用nginx -V来查看

#./configure --user=nginx --group=nginx --with-http_ssl_module

4、源码编译make,但是不安装!

#make

5、编译完之后,进入到源码包的objs目录下,有nginx主程序,把主程序替换老的nginx主程序

[[email protected] nginx-1.12.2]# cd objs/
[[email protected] objs]# ls
autoconf.err  Makefile  nginx  nginx.8  ngx_auto_config.h  ngx_auto_headers.h  ngx_modules.c  ngx_modules.o  src
[[email protected] objs]# cp nginx /usr/local/nginx/sbin/

6、在1.12.2目录下执行升级脚本make upgrade,也可以不执行这个命令,这个是一个脚本,kill nginx进程然后在重新启动nginx也是可以的

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

7、检查版本

# nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --with-http_ssl_module

升级成功,从1.10.3升级到1.12.2

注意事项:

1、升级前一定要备份老的主程序!

2、在源码编译的时候不要执行make install!

3、objs目录是在执行make命令之后源码转换成二进制所放的目录,一般主程序都放在该目录下!

原文地址:https://www.cnblogs.com/BadManWM/p/12182376.html

时间: 2024-08-25 17:45:52

【Nginx】源码安装Nginx 平滑升级Nginx的相关文章

nginx 源码安装以及后续升级https

事情的来源是,公司要将网站从http升级到https,由于历史遗留原因,才发现现有的nginx是通过源码安装的,并没有安装ssl模块,需要现安装sll模块,这个nginx是整个公司最前端的一个代理,涉及到很多部门,因为之前没有操作过,还是小心点为妙,下面是在虚拟机上演示的. 1,先安装后面所需的一些包 yum install gcc-c++ yum install pcre pcre-devel yum install zlib zlib-devel yum install openssl op

Nginx源码安装及调优配置(转)

导读 由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前的优化 [[email protected] ~]# wget http://nginx.org/download/nginx-1.10.1.tar.gz [[email protected] ~]# tar xvf nginx-1.10.1.tar.gz -C /usr/local/src/ [[em

LAMP环境部署:Apache源码安装+MySQL二进制安装+PHP源码安装+Nginx源码安装

Apache 版本:2.2.27 MySQL 版本:5.5.54-linux2.6-x86_64PHP 版本:5.3.27一.源码安装Apache1.首先安装上传工具2.上传LAMP环境所需安装包3.解压所有安装包4.安装Apache依赖包5.创建安装目录6.配置安装文件./configure \ #./configure 是用来生成Makefile文件用于编译安装 --prefix=/application/apache-2.2.27 \ #指定安装目录--enable-deflate \ #

nginx 源码安装openssl修复Heartbleed漏洞

如果你的nginx使用的是动态的openssl库,直接升级openssl,如果你的nginx使用的是静态的openssl库,那就要重新编译安装nginx. PHP编译修复 1. nginx使用的是动态的openssl库,直接升级openssl    1.1 源码安装openssl1.0.1g版本        先下载openssl 1.0.1g版本,命令如下:            #wget  -c    https://www.openssl.org/source/openssl-1.0.1

图解Linux下源码安装PHP7.0.9 +Nginx

上一次,在<Linux下源码安装php7.0.6>,安装过PHP7.0.3,本文将记录安装PHP7.0.9过程. 测试环境 Linux 2.6.32-279.el6.i686 nginx-1.9.15.tar http://nginx.org/download/nginx-1.9.15.tar.gz php-7.0.9.tar.gz http://am1.php.net/distributions/php-7.0.9.tar.gz 安装Nginx wget http://nginx.org/d

nginx 源码安装

安装nginx 安装pcre库是为了让nginx支持具备URI重写功能的rewrite模块 [[email protected] ~]# yum install pcre pcre-devel -y [[email protected] ~]# rpm -qa pcre pcre-devel 安装nginx 依赖的包 openssl-devel [[email protected] ~]# yum install openssl openssl-devel [[email protected]

NGINX源码安装配置详解(./configure),最全解析

NGINX ./configure详解 在"./configure"配置中,"--with"表示启用模块,也就是说这些模块在编译时不会自动构建"--without"表示禁用模块,也就是说这些模块在编译时会自动构建,若你想Nginx轻量级运行,可以去除一些不必要的模块. [[email protected] nginx-1.14.0]# ./configure --help => 查看安装配置项 --help 打印帮助信息. --prefix

nginx源码安装(CentOS版)

准备工作: 1) 配好网易yum源 登录此网站(http://mirrors.163.com/.help/centos.html),下载相应版本的yum源至服务器的/etc/yum.repos.d/目录下,然后按照此步骤进行操作,即可完成网易yum源的配置准备. 2) 安装make/gcc/zlib等安装包 yum install -y gcc automake autoconf libtool make yum install -y gcc gcc-c++ 开始: 1) 选定源码目录 cd /

nginx源码安装

1.安装开发包 # yum install -y pcre-devel openssl-devel 2.解压源码包并编辑文件隐藏nginx版本 # tar zxvf nginx-1.8.0.tar.gz #  cd nginx-1.8.0 #  vim auto/cc/gcc #CFLAGS="$CFLAGS -g"               #注释掉这行,去掉debug模式编译,编译以后程序只有几百k # vim src/core/nginx.h #define NGINX_VER

Centos下Nginx源码安装与配置并附shell编程实现自动化安装

一.首先安装必要的库 nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库.选定/usr/local为安装目录,以下具体版本号根据实际改变. 1.安装PCRE库 $ cd /usr/local/ $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz $ tar -zxvf pcre-8.36.tar.gz $ cd pcre-8.3