linux nginx启动脚本
时间: 2023-10-13 20:19:02 浏览: 53
Linux中启动Nginx的脚本通常是一个位于/etc/init.d目录下的文件。以下是一个示例的Nginx启动脚本:
```shell
#!/bin/bash
#
# Nginx startup script
# Nginx安装路径
nginx_path="/usr/local/nginx"
# 启动函数
start() {
echo "Starting Nginx..."
${nginx_path}/sbin/nginx
}
# 停止函数
stop() {
echo "Stopping Nginx..."
${nginx_path}/sbin/nginx -s stop
}
# 重启函数
restart() {
stop
sleep 1
start
}
# 根据输入的参数调用相应的函数
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
```
你可以将以上脚本保存为例如`nginx.sh`,然后使用以下命令来执行脚本:
```shell
chmod +x nginx.sh # 赋予执行权限
./nginx.sh start # 启动Nginx
./nginx.sh stop # 停止Nginx
./nginx.sh restart # 重启Nginx
```
希望对你有所帮助!如果还有其他问题,请继续提问。