一、Nginx解压
nginx-1.18.0.zip在C盘根目录解压,得到nginx-1.18.0文件夹
二、端口占用检查
netstat -ano 查看80端口是否被占用,没有则直接执行Step4步
三、Nginx配置更改
修改配置文件C:\nginx-1.18.0\conf\nginx.conf,默认监听的端口由80转为8800(全局搜索关键字80替换为8800或者直接修改初始配置文件第36行listen 80;为listem 8800)
四、Nginx启动
进入cmd命令界面,依次键入命令
cd C:/nginx-1.18.0
nginx -t -c /nginx-1.18.0/conf/nginx.conf //检查配置文件是否有误
start nginx
--------------------------------------------------------------
nginx -s reload //重新载入
nginx -s stop //停止服务
tasklist /fi "imagename eq nginx.exe" //可查看Nginx服务启动情况
https://localhost:8083/
五、Bash脚本自行安装
:: 关闭回显,即执行本脚本时不显示执行路径和命令,直接显示结果
@echo off
chcp 65001
color f8
set NGINX_DIR=D:\nginx-1.18.0\
if exist "D:\nginx-1.18.0" (
echo "The installation file already exists, proceed to the next step"
) else (
xcopy /e /i %~dp0\nginx-1.18.0 D:\nginx-1.18.0
echo "File transfer completed"
)
:INFO
echo.
echo --------------------- Process List ---------------------
tasklist|findstr /i "nginx.exe"
if errorlevel 1 echo Nginx unstart
echo --------------------- Process List ---------------------
echo.
echo. 1. Start Nginx
echo. 2. Close Nginx
echo. 3. Restart Nginx
echo. 4. Exit
echo.
echo Please enter the function number:
set /p id=
if "%id%"=="1" goto START
if "%id%"=="2" goto STOP
if "%id%"=="3" goto RESTART
if "%id%"=="4" exit
pause
:START
if exist "%NGINX_DIR%nginx.exe" (
cd /d %NGINX_DIR%
start "" nginx.exe
echo Start-up success
) else (
echo "%NGINX_DIR%nginx.exe not exist"
)
goto INFO
:STOP
taskkill /F /IM nginx.exe > nul
echo All Nginx processes have been closed
goto INFO
:RESTART
taskkill /F /IM nginx.exe > nul
if exist "%NGINX_DIR%nginx.exe" (
cd /d %NGINX_DIR%
start "" nginx.exe
) else (
echo "%NGINX_DIR%nginx.exe not exist"
)
echo Already Restart
goto INFO
goto :eof