一、yum安装
1.下载安装nginx 的软件源
[root@localhost ~]# wget https://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@localhost ~]# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
2. 安装nginx
[root@localhost ~]# yum install -y nginx
二、源码安装
1.安装依赖环境、库
gcc环境、pcre重写功能、压缩解压缩库zlib、安全套接字层密码库openssl
[root@localhost nginx]# yum install -y gcc gcc-c++ autoconf automake make pcre pcre-devel zlib zlib-devel make libtool openssl-devel
2.创建用户和用户组
[root@localhost ~]# useradd nginx
[root@localhost ~]# groupadd nginx
3.下载、解压并编译对应版本压缩包(我这里是1.18.0)
[root@localhost ~]# wget https://nginx.org/download/nginx-1.18.0.tar.gz
[root@localhost ~]# tar zxf nginx-1.18.0.tar.gz
[root@localhost ~]# cd nginx-1.18.0/
##检查安装环境
[root@localhost nginx-1.18.0]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --user=nginx --group=nginx --with-cc-opt="-Wno-error=deprecated-declarations"
[root@localhost nginx-1.18.0]# make #编译
[root@localhost nginx-1.18.0]# install #安装