Nginx配置systemctl管理

Nginx管理的命令

#启动
/usr/sbin/nginx -c /etc/nginx/nginx.conf

#重新加载配置文件
/usr/sbin/nginx -s reload

#停止退出
/usr/sbin/nginx -s stop
/usr/sbin/nginx -s quit

配置文件


[root@ALiYunOgenes ~]# systemctl status nignx
Unit nignx.service could not be found.

#查看nginx路径
[root@ALiYunOgenes ~]# which nginx
/usr/sbin/nginx

#查看nginx配置文件路径
[root@ALiYunOgenes ~]# nginx -t              
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
#查看pid路径
[root@ALiYunOgenes ~]# grep pid /etc/nginx/nginx.conf    
pid        /var/log/nginx/nginx.pid;

#注意修改nginx和配置文件和pid的路径
[root@ALiYunOgenes ~]# vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/home/run/nginx/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s stop
ExecQuit=/usr/sbin/nginx -s quit

[Install]
WantedBy=multi-user.target

启动nginx

[root@ALiYunOgenes ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Dec 17 17:21:48 ALiYunOgenes systemd[1]: [/usr/lib/systemd/system/nginx.service:12] Unknown lvalue 'ExecQuit' in section 'Service'

[root@ALiYunOgenes ~]# systemctl start nginx

设置开机自启动

[root@ALiYunOgenes ~]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@ALiYunOgenes ~]# systemctl is-enabled nginx
enabled

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值