Nginx2 自动启动脚本

防火墙

systemctl stop firewalld.service 关闭防火墙
systemctl disable firewalld.service 禁止防火墙开机启动
firewalld-cmd --zone=public --add-port=80/tcp --permanent 放行端口
firewalld-cmd --reload 重启防火墙

Nginx

进入Nginx目录/usr/local/nginx/sbin

./nginx 启动
./nginx -s stop 快速停止
./nginx -s quit 优雅关闭,在退出前完成已经接受的连接请求(做完没有完成的任务后,关闭)
./nginx -s reload 重新加载配置

脚本启动Nginx服务

创建服务脚本

vi /usr/lib/systemd/system/nginx.service

脚本内容

[Unit] 
Description=nginx
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
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
ExecQuit=/usr/local/nginx/sbin/nginx -s quit 
PrivateTmp=true

[Install]   
WantedBy=multi-user.target  # 多用户

重新加载系统服务

systemctl daemon-reload 

启动服务

systemctl start nginx.service

好像有报错耶,报错信息如下:

nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

直接使用kill -9 {nginx进程号}删除即可(ps -ef | grep nginx)可以查询进程号,然后在进行nginx重启操作

需要去/usr/local/nginx/conf文件下,修改nginx.conf,把配置中的pid一项打开,即去掉#,如图所示:

image-20221102205913715


开机启动

systemctl enable nginx.service

Nginx基本目录结构

image-20221102214542599

Nginx运行进程

image-20220502111337135

image-20221102215318532

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值