环境准备
yum -y install gcc-c
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
下载nginx
官网下载nginx版本 http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.7.4.tar.gz
编译安装
tar -zxvf nginx-1.7.4.tar.gz
cd nginx-1.7.4
./configure --prefix=/usr/local/nginx
make && make install
nginx开机自动启动
在这里我是用源码编译安装的,所以要手动创建nginx.service服务文件。
开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即:
/lib/systemd/system/nginx.service
在系统服务目录里创建nginx.service文件
vim /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 reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
设置开机启动
systemctl enable nginx.service
其他命令
systemctl start nginx.service 启动nginx
systemctl stop nginx.service 结束nginx
systemctl restart nginx.service 重启nginx
systemctl status nginx.service 查看服务当前状态
systemctl list-units --type=service 查看所有已启动的服务
systemctl disable nginx.service 停止开机自启动
参考文章centos 7.x编写开机启动服务,centos 7 安装 nginx