1.安装依赖
yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel
2.下载稳定版nginx
nginx.org
3.创建nginx管理用户
useradd nginx -s /sbin/nologin -M
4.解压到/usr/local/src,进入目录,编译
(1)./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.16.0/ --with-http_ssl_module --with-http_stub_status_module
(2)make && make install
5.创建目录,创建软链
mkdir /data/service
ln -s /usr/local/nginx-1.16.0/ /data/service/nginx
- 创建开机启动
(1)vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx-1.16.0/logs/nginx.pid
ExecStartPre=/usr/local/nginx-1.16.0/sbin/nginx -t -c /usr/local/nginx-1.16.0/conf/nginx.conf
ExecStart=/usr/local/nginx-1.16.0/sbin/nginx -c /usr/local/nginx-1.16.0/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
(2)systemctl enable nginx.service
systemctl start nginx.service
注:如果修改了systemctl文件,需要重载
执行systemctl daemon-reload
[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3