centOS 7 安装nginx服务

一、安装相关依赖

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 

 

 

 

 

 

 

posted @ 2019-10-04 21:57  李小加  阅读(678)  评论(0编辑  收藏  举报