linux配置nginx开机启动
一、方法一
1.找到/etc/rc.local文件,在文件最后一行新增启动命令(nginx默认安装目录为:/usr/local/nginx):
/usr/local/nginx/sbin/nginx
二、方法二
1.进入/etc/systemd/system文件夹,新增文件 nginx.service
2.文件内容:
[Unit]
Description=nginx service
After=network.target
[Service]
User=root
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecStartPre=/bin/sleep 10
[Install]
WantedBy=multi-user.target
3.开启开机启动
systemctl enable nginx