CentOS7添加Nginx为系统服务

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7添加Nginx为系统服务相关的知识,希望对你有一定的参考价值。

1.编辑系统服务

vim /usr/lib/systemd/system/nginx.service 
[unit]
Description=Web Service
After=network.target
[Service]
PIDFile=/var/run/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload
PrivateTmp=true
[INSTALL]
WantedBy=default.target

2.修改权限

chmod 755 /usr/lib/systemd/system/nginx.service

3.测试是否成功

[[email protected] ~]# systemctl start nginx 
[[email protected] ~]# systemctl status nginx
● nginx.service
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; static; vendor preset: disabled)
   Active: active (running) since Wed 2017-07-26 15:37:34 CST; 8min ago
  Process: 24964 ExecReload=/usr/local/nginx/sbin/nginx -s reload (code=exited, status=0/SUCCESS)
 Main PID: 24956 (nginx)
   CGroup: /system.slice/nginx.service
           ├─24956 nginx: master process /usr/local/nginx/sbin/ngin...
           └─24965 nginx: worker process
Jul 26 15:37:34 nginx systemd[1]: Started nginx.service.
Jul 26 15:37:34 nginx systemd[1]: Starting nginx.service...
Jul 26 15:37:36 nginx systemd[1]: Reloaded nginx.service.
[[email protected] ~]# systemctl reload nginx
[[email protected] ~]# ss -tln
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128     *:80                  *:*                  
LISTEN     0      128     *:22                  *:*                  
LISTEN     0      100    127.0.0.1:25                  *:*                  
LISTEN     0      128    :::22                 :::*                  
LISTEN     0      100       ::1:25                 :::*
[[email protected] ~]# systemctl stop nginx
[[email protected] ~]# systemctl status nginx
● nginx.service
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; static; vendor preset: disabled)
   Active: inactive (dead)
Jul 26 15:37:36 nginx systemd[1]: Reloaded nginx.service.
Jul 26 15:46:16 nginx systemd[1]: Reloaded nginx.service.
Jul 26 15:46:47 nginx systemd[1]: Stopping nginx.service...
Jul 26 15:46:47 nginx systemd[1]: Stopped nginx.service.
Jul 26 15:46:47 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Jul 26 15:46:47 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Jul 26 15:46:47 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Jul 26 15:46:47 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Jul 26 15:46:49 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Jul 26 15:46:49 nginx systemd[1]: [/usr/lib/systemd/system/nginx.s....
Hint: Some lines were ellipsized, use -l to show in full.
[[email protected] ~]# systemctl enable nginx


本文出自 “有趣灵魂” 博客,请务必保留此出处http://powermichael.blog.51cto.com/12450987/1950925

以上是关于CentOS7添加Nginx为系统服务的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7.4 Nginx添加系统服务及开机自启动

centos7下nginx添加到自定义系统服务中提示Access denied

Eg挨蒙—阿里云Centos7部署Lnmp+Zabbix+Grafana监控系统

Flask+uWSGI+Nginx项目部署

CentOS7+Nginx设置Systemctl restart nginx.service服务

Centos7 nginx 搭建https服务器