1、nginx 安装目录 /usr/local/nginx
2、nginx 可执行程序目录 /usr/local/nginx/sbin
3、nginx.conf 目录 /usr/local/nginx/conf 可以指定pid文件位置
4、nginx.pid 目录 /usr/local/nginx/pid
user www www;
worker_processes auto;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/pid/nginx.pid; #这里
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
cd /usr/lib/systemd/system
vim nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/pid/nginx.pid # pid 文件
ExecStartPre=/usr/bin/rm -f /usr/local/nginx/pid/nginx.pid # pid 文件
ExecStartPre=/usr/bin/nginx -t # nginx 软链接文件
ExecStart=/usr/bin/nginx # nginx 软链接文件
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable nginx.service
#启动nginx服务
systemctl start nginx
#停止nginx服务
systemctl stop nginx
#重启nginx服务
systemctl restart nginx
#加载nginx配置
systemctl reload nginx