1.安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel
2.解压Nginx安装包
tar -zxvf nginx-1.18.0.tar.gz -C /usr/local/
当前安装包所在的目录:/usr/local/
3.进入安装包目录
cd nginx-1.18.0
4、编译安装
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make&make install
5.测试是否安装成功
#cd到刚才配置的安装目录
# cd /usr/local/nginx
./sbin/nginx -v
6.添加nginx用户
groupadd nginx
useradd -g nginx nginx
7.配置nginx.conf
./sbin/nginx -t
#或者 /usr/local/nginx/sbin/nginx -t
找到nginx.conf的路径:/usr/local/nginx/conf/nginx.conf
# vi ./conf/nginx.confg
#vi /usr/local/nginx/conf/nginx.conf
测试一般不用更改
7.启动Nginx(默认端口是80)
./sbin/nginx
# /usr/local/nginx/sbin/nginx
关闭:nginx -s stop
重新载入配置文件:nginx -s reload
8.配置nginx开机自启动
vi /etc/rc.d/rc.local
#添加/usr/local/nginx/sbin/nginx
9.配置全局
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/