1.下载nginx
[root@centos]# wget http://nginx.org/download/nginx-1.13.3.tar.gz
2.解压nginx到 /tmp 目录下
[root@centos]# tar -zxvf nginx-1.13.3.tar.gz
[root@centos]# cd nginx-1.13.3
3.编译安装nginx
[root@centos]# ./configure
[root@centos]# make && make install
[root@centos]# whereis nginx
4.在/usr/lib/systemd/system/目录下创建nginx.service
[root@centos]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
更改文件权限
[root@centos]# chmod 745 /usr/lib/systemd/system/nginx.service
常用命令
[root@centos]# systemctl enable nginx.service # 设置开机自启动
[root@centos]# systemctl start nginx.service # 启动服务
[root@centos]# systemctl stop nginx.service # 停止服务
[root@centos]# systemctl restart nginx.service # 重启服务
[root@centos]# systemctl status nginx.service # 检查状态
ps: 如果出现没有权限在 conf 文件开头加上 use root;
use root;