先安装gcc-c++编译器
java
yum install gcc-c++
java
yum install -y openssl openssl-devel
安装pcre包
java
yum install -y pcre pcre-devel
安装zlib包
java
yum install -y zlib zlib-devel
在/usr/local/创建nginx文件
java
mkdir /usr/local/nginx
进入nginx目录
java
cd /use/local/nginx
下载nginx安装包
java
wget https://nginx.org/download/nginx-1.19.9.tar.gz
注:如果没有wget命令,就安装命令
java
yum install wget
解压安装包
java
tar -zxvf nginx-1.19.9.tar.gz
java
cd nginx-1.19.9
执行以下三个命令
java
./configure
java
make
java
make install
添加到系统服务中
java
vim /etc/profile
最后加入配置
java
export PATH=/usr/local/nginx/sbin:$PATH
重载配置
java
source /etc/profile
添加systemctl命令
java
vi /usr/lib/systemd/system/nginx.service
添加内容
java
[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载系统服务
java
systemctl daemon-reload
启动服务
java
systemctl start nginx
停止服务
java
systemctl stop nginx
重启服务
java
systemctl restart nginx
重载配置文件
java
nginx -s reload