centos7下nginx-1.18.0安装
1、下载安装包
进入官网(http://nginx.org/en/download.html)下载指定版本的安装包,这里下载的是nginx-1.18.0.tar.gz
2、解压压缩文件
tar zxf nginx-1.18.0.tar.gz
cd nginx-1.18.0
3、编译安装nginx
3.1 环境的安装
sudo yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
3.2 编译安装nginx
sudo useradd -M -s /sbin/nologin nginx
sudo ./configure --prefix=/usr/local/nginx --user=nginx
sudo make && sudo make install
cd /usr/local/nginx/
ll
4、设置服务
将nginx制作成服务,并设置开机启动(centos7):
sudo vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start nginx.service
sudo systemctl enable nginx.service