一、安装相关依赖
yum install gcc-c++ yum install -y pcre pcre-devel yum install -y zlib zlib-devel yum install -y openssl openssl-devel
二、到官网下载安装包进行安装
到官网下载tar.gz
安装包,地址:https://nginx.org/en/download.html
tar -zxvf nginx-1.16.1.tar.gz cd nginx-1.16.1.tar.gz ./configure make make install whereis nginx
三、设置开机自启动
在/usr/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
取消开机自启动:
systemctl disable nginx
四、服务操作命令
启动nginx服务
# systemctl start nginx.service
停止服务
# systemctl stop nginx.service
重新启动服务
# systemctl restart nginx.service
查看服务当前状态
# systemctl status nginx.service
原文地址:https://www.cnblogs.com/101key/p/11623456.html
时间: 2024-10-18 09:55:08