当前位置:首页 > nginx > 正文

linux设置nginx开机自启动(linux设置程序开机自启动)

  • nginx
  • 2024-03-15 19:33:31
  • 1382
Linux 设置 Nginx 开机自启动
方法:
1. 创建 Nginx 服务文件
shell
sudo nano /etc/systemd/system/nginx.service
2. 添加以下内容:
[Unit]
Description=The Nginx HTTP and reverse proxy server
After=network.target
[Service]
Type=forking
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3. 保存文件并退出
shell
Ctrl + O
Enter
Ctrl + X
4. 重载 systemd
shell
sudo systemctl daemon-reload
5. 启用 Nginx 服务
shell
sudo systemctl enable nginx
6. 启动 Nginx 服务
shell
sudo systemctl start nginx
检查是否成功:
检查 Nginx 是否正在运行:
shell
sudo systemctl status nginx
检查开机自启动是否生效:
shell
sudo systemctl is-enabled nginx