- 安装依赖库
yum -y install pcre-devel
yum -y install openssl openssl-devel
yum -y install gcc-c++
- 下载安装包,并解压
tar -zxvf nginx-*.tar.gz -C 目标目录
- 安装,进入到解压目录下,执行安装命令(如果需要安装额外的模块,在需在./configure后面加参数)
./configure
make && make install
- 设置开机自启动
在/lib/systemd/system
目录下,建nginx.service
文件
[Unit]
Description=nginx service
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
- 将命令添加到服务中
systemctl enable nginx.service
- 启动
systemctl start nginx.service
网友评论