系统添加Nginx(简单,实用,顺手)
系统添加Nginx(源码包安装,以systemctl形式启动)
0.环境准备:源码安装好nginx
1.创建nginx.service文件
vi /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/sbin/nginx #启动(这里不是nginx的默认地址,/usr/local/nginx/sbin/nginx是它的默认安装地址)
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2.以systemctl方式启动nginx
pkill nginx #杀掉原来开启的nginx
systemctl daemon-reload #重新加载配置信息
systemctl start nginx #开启nginx
3.检查nginx是否启动
netstat -ntlp | grep nginx
systemctl status nginx
4.设置开机自启
systemctl enable nginx
感谢大家,点赞,收藏,关注,评论!