windows用bat脚本将nginx安装为服务

首先可以从百度网盘下载nginx文件包:
链接:https://pan.baidu.com/s/1XP1jXBfFLmyOeAi3cMkvOw?pwd=re0z 
提取码:re0z

安装脚本如下:

@echo off
chcp 65001

echo 参数设置
echo.
set cds=%~dp0
echo 当前目录:%cds%

echo ****************************************
echo.
echo 安装nginx,请不要关闭窗口
echo.
echo.
echo 请以管理员身份运行
echo.
echo ****************************************

echo 参数设置
echo.
set cdsf=%cds:\=/%
set sign=${base}
set nginxpath=%cdsf%nginx
echo nginx目录:%nginxpath%
set teamplatefile=%nginxpath%/conf/nginx.conf.template
echo 模版目录:%teamplatefile%
set configfile=%nginxpath%/conf/nginx.conf
set configfileremove=%cds%nginx\conf\nginx.conf
echo 模版目录:%configfile%
echo 模版删除目录:%configfileremove%
set servertemplatefile=%cds%nginx\nginx-service.xml.template
echo 服务模版目录:%servertemplatefile%
set serverfile=%cds%nginx\nginx-service.xml
echo 服务文件目录:%serverfile%

echo 删除旧配置文件
echo.
if exist %configfileremove% del %configfileremove%
if exist %serverfile% del %serverfile%

echo 生成配置文件
echo.
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in (%teamplatefile%) do (
set s=%%i
set s=!s:%sign%=%cds%!
if not [!s!]==[] echo !s!>>%configfile%
)

for /f "tokens=*" %%j in (%servertemplatefile%) do (
set t=%%j
set t=!t:%sign%=%cds%!
if not [!t!]==[] echo !t!>>%serverfile%
)

echo 安装nginx服务
%cds%nginx\nginx-service.exe install
sc start xxx_nginx


exit

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凌晨两点钟同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值