最后的几行是配置的结果, 注意这里的 pid file 那一行,后面配置服务的时候,需要用的到。
安装 Nginx
使用如下命令来安装 nginx 。
make && make install
配置 systemd Nginx 服务和设置 Nginx 自启动
centos 7 中采用 systemd 来管理系统,我们来为 nginx 创建服务文件,来实现通过 systemd 来管理 nginx 。
创建 systemd 服务文件: /lib/systemd/system/nginx.service,内容如下:
[Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
这里的 PIDFile 的配置要和前面的 配置保持一致。
设置自启动
systemctl enable nginx
通过 systemd 管理 nginx
systemctl start nginx systemctl stop nginx systemctl restart nginx systemctl reload nginx
总结
好了,打完收工。以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对易采站长站的支持。








