RHEL6
安装依赖
yum install -y gcc gcc-c++ make automake autoconf pcre pcre-devel zlib zlib-devel openssl openssl-devel
下载nginx源码包
wget http://nginx.org/download/nginx-1.18.0.tar.gz
解压资源包
tar -zxvf nginx-1.18.0.tar.gz
进入nginx源码目录
cd nginx-1.18.0
配置编译参数
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
编译安装
make && make install
设置开机自启动
echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local
chmod +x /etc/rc.local
RHEL7
安装依赖
yum install -y gcc gcc-c++ make automake autoconf pcre pcre-devel zlib zlib-devel openssl openssl-devel
下载nginx源码包
wget http://nginx.org/download/nginx-1.18.0.tar.gz
解压
tar -zxvf nginx-1.18.0.tar.gz
进入nginx源码目录
cd nginx-1.18.0
配置编译参数
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
编译安装
make && make install
创建nginx服务的systemd脚本
cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=The nginx HTTP Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
重载systemd配置
systemctl daemon-reload
启动nginx服务
systemctl start nginx
设置开机自启动
systemctl enable nginx