1 在usr/local下 tar -zxvf nginx-1.22.1.tar.gz
重命名 mv /usr/local/nginx-1.22.1 /usr/local/nginx
修改配置文件/conf/nginx.conf
2 创建sbin目录
在nginx目录下,输入命令bash ./configure --prefix=/usr/local/nginx
bash的作用是避免权限不足,导致无法执行以上命令
其中后面的/usr/local/nginx,可以是你的nginx目录,会将后续生成的文件存放到这个目录。
3.执行make
4.执行make install
5 /usr/local/nginx下创建logs目录, mkdir logs
进入sbin目录,执行 ./nginx即可。完成启动
配置nginx开机自启
1 新建 vim /usr/lib/systemd/system/nginx.service
2 nginx.service输入
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
说明:
Description:描述服务
After:依赖,当依赖的服务启动之后再启动自定义的服务
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令(需要根据路径适配)
ExecReload为重启命令(需要根据路径适配)
ExecStop为停止命令(需要根据路径适配)
PrivateTmp=True表示给服务分配独立的临时空间
注意:启动、重启、停止命令全部要求使用绝对路径
[Install]服务安装的相关设置,可设置为多用户
3 输入相应命令
systemctl disable nginx.service 关闭开机自启
systemctl enable nginx.service 开启开机自启
systemctl status nginx.service 查看状态
systemctl restart nginx.service 重启服务
systemctl list-units --type=service 查看所有服务