安装nginx需要一些环境支持
GCC用来对nginx源码进行编译
yum -y install gcc-c++
Nginx的Rewrite模块和HTTP核心模块会使用到PCRE正则表达式语法。
这里需要安装两个安装包pcre和pcre-devel。
第一个安装包提供编译版本的库,而第二个提供开发阶段的头文件和编译项目的源代码。
yum install -y pcre pcre-devel
zlib库提供了开发人员的压缩算法,在Nginx的各种模块中需要使用gzip压缩.
yum install -y zlib zlib-devel
nginx不仅支持 http协议,还支持 https(即在 ssl 协议上传输 http)。
如果使用了 https,需要安装 OpenSSL 库.
yum install -y openssl openssl-devel
官网下载地址: https://nginx.org/en/download.html
选择稳定版本

curl -O https://nginx.org/download/nginx-1.22.0.tar.gz
tar -zxvf nginx-1.22.0.tar.gz
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
cd /usr/local/nginx/sbin
./nginx
Nginx默认为80端口,启动后可以在浏览器输入自己的ip和端口号进行验证是否启动成功。

vi /etc/profile
添加nginx路径。

刷新配置文件
source /etc/profile
nginx -v
nginx version: nginx/1.22.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module