安装依赖
yum -y install gcc-c++ pcre-devel openssl openssl-devel
下载源码nginx包
wget http://nginx.org/download/nginx-1.22.0.tar.gz
解压源码包
tar -zxvf nginx-1.22.0.tar.gz
配置编译参数
cd nginx-1.22.0
./configure --prefix=/data/nginx --with-http_ssl_module --with-http_stub_status_module
编译并安装
make && make install
nginx启动、停止、重新加载
启动
/data/nginx/sbin/nginx
停止
/data/nginx/sbin/nginx -s stop
重新加载
/data/nginx/sbin/nginx -s reload
配置nginx开机自启动
vim /etc/systemd/system/nginx.service
[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
开启开机自启动
systemctl enable nginx.service
关闭开机自启动
systemctl disable nginx.service
还可以用systemctl方式启动、停止、重启
启动
systemctl start nginx.service
停止
systemctl stop nginx.service
重启
systemctl restart nginx.service
查看nginx状态
systemctl status nginx.service
其他命令
查看配置文件是否正确
/data/nginx/sbin/nginx -t
查看nginx版本信息
/data/nginx/sbin/nginx -v
查看nginx编译参数
/data/nginx/sbin/nginx -V