1.安装前确认
安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel
安装命令
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
2.下载和安装
#下载nginx
wget http://nginx.org/download/nginx-1.21.3.tar.gz
#解压
tar -zxvf nginx-1.21.3.tar.gz
#配置
cd nginx-1.21.3
./configure --prefix=/usr/local/nginx
#make
make
make install
3.安装验证
cd /usr/local/nginx
sbin/nginx -t
正常输出内容如下:
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
4.添加nginx环境变量
修改/etc/profile文件,在文件末尾追加以下内容
PATH=$PATH:/usr/local/nginx/sbin
export PATH
5.nginx异常处理
5.1.nginx unknown directive “stream”
nginx默认安装的时候没有加载stream模块
需要重新对源文件进行编译、安装,通过添加–with-stream参数指定安装stream模块
./configure --with-stream --prefix=/usr/local/nginx
make & make install
再次检查nginx.conf配置文件,确认配置无语法错误后,再次尝试启动服务。
nginx -t 检查配置文件是否正确
nginx -c 指定启动的配置文件x/logs/nginx.pid;