Nginx 开机自启动

本文介绍了Nginx的开机自启动配置方法,包括使用vim编辑配置文件、设置执行权限、添加到开机启动列表,以及通过systemd管理Nginx服务。同时提醒修改配置后需重新加载配置文件,确保生效。文中还提及了适用于redis的类似配置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Nginx 开机自启动

Nginx 启动、停止、重启脚本配置

  1. 先停止Nginx
sudo kill `cat /usr/local/nginx/logs/nginx.pid
  1. 创建脚本
vi /etc/init.d/nginx

创建的文件输入以下内容:

#!/bin/bash
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

## 此文件可以根据 安装的nginx 改变而进行修改
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)  ## 获取nginx 名称
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx

start() {
   
      [ -x $nginx
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值