@echo off
:: 设置 nginx 的安装目录(请根据实际情况修改)
set NGINX_PATH=C:\Program Files\nginx\nginx-1.25.3
title Nginx 控制面板
:start
cls
echo.
echo ================== Nginx 控制菜单 ==================
echo.
echo 1. 启动 Nginx
echo 2. 关闭 Nginx
echo 3. 重启 Nginx
echo 4. 查看 Nginx 运行状态
echo 5. 退出
echo.
set /p choice=请输入选项 (1-5):
if "%choice%"=="1" goto start_nginx
if "%choice%"=="2" goto stop_nginx
if "%choice%"=="3" goto restart_nginx
if "%choice%"=="4" goto check_status
if "%choice%"=="5" exit
echo 无效的输入,请重新选择。
pause
goto start
:start_nginx
echo 正在启动 Nginx...
cd /d "%NGINX_PATH%"
start nginx
echo Nginx 已启动。
pause
goto start
:stop_nginx
echo 正在停止 Nginx...
taskkill /f /im nginx.exe >nul 2>&1
echo Nginx 已停止。
pause
goto start
:restart_nginx
echo 正在重启 Nginx...
call :stop_nginx
timeout /t 2 >nul
call :start_nginx
echo Nginx 已重启。
pause
goto start
:check_status
echo 正在检查 Nginx 是否运行...
tasklist | findstr /i "nginx.exe" >nul 2>&1
if %errorlevel% == 0 (
echo Nginx 正在运行。
) else (
echo Nginx 未运行。
)
pause
goto start
如果中文显示乱码,文件另存为,编码设置成ANSI