浏览 3.8k
NGINX安装好后,我们都希望配置当系统启动后,能自动启动NGINX服务,在Linux系统中,现在比较多采用systemd来管理服务的启停,以下为在CentOS 7上通过systemd配置开机直接启动NGINX服务的一些操作:
1.
在CentOS7上采用yum命令安装NGNIX Plus的过程,可参考:
https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-plus/#install_rhel_centos
安装完成后,系统会自动在/lib/system/system目录下生成nginx.service文件:

采用Systemctl enable命令直接配置系统启动时启动NGINX服务即可:
[root@nginxplus2-14 ~]# systemctl enable nginx.service
2.
在CentOS7上采用yum安装NGINX Open Source版本的过程,可参考:
安装完成后,系统会自动在/lib/system/system下生成nginx.service文件:
采用Systemctl enable命令直接配置系统启动时启动NGINX服务即可:
[root@nginxoss-2-15 system]# systemctl enable nginx.service

3.
自己编译安装NGINX Open Source,请参考:
https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#sources
完装完成后,需要自己手工创建生成/lib/systemd/system/nginx.service文件(请根据自己的环境修改PIDfile和nginx命令的路径):

采用Systemctl enable命令直接配置系统启动时启动NGINX服务:
[root@nginxoss1 system]# systemctl enable nginx.service
可以采用systemctl is-enabled命令来检查nginx服务是否enable:
[[root@nginxoss-2-15 system]# systemctl is-enabled nginx.service
enabled

按点赞数排序
按时间排序
微信公众号
加入微信群