要在Ubuntu上設(shè)置Nginx自啟動(dòng),您可以按照以下步驟操作:
systemd
工具:sudo apt-get install systemd
nginx.service
文件:sudo nano /etc/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=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=/usr/sbin/nginx -g 'daemon on; master_process on;' -s quit
[Install]
WantedBy=multi-user.target
sudo systemctl enable nginx.service
sudo systemctl start nginx.service
sudo systemctl status nginx.service
現(xiàn)在,Nginx將在Ubuntu啟動(dòng)時(shí)自動(dòng)啟動(dòng)。