yum 和 源码安装的区别
yum 安装是在线安装,优点:安装方式简单,快捷;
源码安装是将源码进行编译,生成可执行文件,优点:方便的添加模块等
yum安装nginx
系统版本:CentOS Linux release 7.4.1708 (Core)
1.增加对应的源
1
   | rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
   | 
 
2.查看nginx信息
1
   | yum info nginx  (查看nginx 版本方便后面下载对应版本)
   | 
 
3.yum安装nginx
nginx 相关的命令
1.查看安装路径
2.查看编译参数
3.nginx 启动、停止、重启
1 2 3
   | systemctl start nginx #启动 nginx 服务 systemctl stop nginx #停止 nginx 服务 systemctl restart nginx #重启 nginx 服务
   | 
 
启动检查是否启动成功
如下显示说明正常启动:
1 2 3
   | ··· <h1>Welcome to nginx!</h1> ···
   | 
 
安装第三方模块
其实yum安装nginx 后想要添加第三方模块,只需对yum安装的nginx相同版本的源码进行编译后替换
1.安装源码安装需要的第三方包
1
   | yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
   | 
 
2.下载对应的源码
通过nginx -V 可以知道yum 安装nginx 的版本为1.12.1,下载对应的源码
1 2
   | cd /opt wget http://nginx.org/download/nginx-1.12.1.tar.gz
   | 
 
1 2 3 4 5 6 7
   | tar xf nginx-1.12.1.tar.gz cd nginx-1.12.1 nginx -V configure arguments:  --prefix=/etc/nginx \             --sbin-path=/usr/sbin/nginx \             --conf-path=/etc/nginx/nginx.conf \             ...
   | 
 
4.增加对应的模块
1 2 3 4 5
   | ./configure --prefix=/etc/nginx \             --sbin-path=/usr/sbin/nginx \             --conf-path=/etc/nginx/nginx.conf \             ...             --add-module=../headers-more-nginx-module
   | 
 
5.编译
6.对可执行文件进行备份替换
1 2 3
   | cp /usr/sbin/nginx /usr/sbin/nginx.bak #备份 cp /opt/nginx-1.12.1/objs/nginx /usr/sbin/nginx #替换 systemctl restart nginx #重启 nginx 服务
   | 
 
大功告成