安装好nginx后,添加到系统服务中
在/usr/lib/systemd/system下创建nginx.service文件内容如下:
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target [Service]
Type=forking
PIDFile=/your nginx pid file path/nginx.pid
ExecStartPre=/your nginx path/sbin/nginx -t -c /your nginx path/conf/nginx.conf
ExecStart=/your nginx path/sbin/nginx -c /your nginx path/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true [Install]
WantedBy=multi-user.target
添加完之后,开启服务
systemctl enable nginx.service
但是提示错误:Access denied
搜了一下原因,是SELinux造成的。解决方案有两种:
一,
systemctl daemon-reexec
二,这种方法会存在安全隐患
setenforce