编译安装nginx

参考:https://blog.csdn.net/lihailin9073/article/details/102535717

 

### online install ###
[root@localhost ~]# yum -y install openssl-devel pcre-devel    //安装环境

[root@localhost ~]# curl -O http://nginx.org/download/nginx-1.16.1.tar.gz    //官网下载nginx安装包
[root@localhost ~]# tar zxf nginx-1.16.1.tar.gz    //解压
[root@localhost ~]# cd nginx-1.16.1    //进入解压后的目录
[root@localhost ~]# ./configure --prefix=/usr/local/nginx    //预编译,设置主文件目录
[root@localhost ~]# make -j4 &&make -j4 install    //安装
[root@localhost ~]# systemctl stop firewalld    //关闭防火墙
[root@localhost ~]# systemctl mask firewalld    //注销防火墙,恢复为 systemctl unmask firewalld

[root@localhost ~]# echo "    //将以下内容输入到/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 reloadchk
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target" > /lib/systemd/system/nginx.service

[root@localhost ~]# systemctl enable nginx    //添加nginx开机启动项

 

####################################################################

Description: 描述
After: 服务类别
Type=forking 后台运行的形式
ExecStart 服务的具体运行命令
ExecReload 重启命令
ExecStop 停止命令
PrivateTmp=True 表示给服务分配独立的临时空间
注意:
[Service] 该服务的启动、重启、停止命令。必须绝对路径。
[Install] 运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

posted @ 2020-10-26 16:10  1420_wafer  阅读(60)  评论(0)    收藏  举报