1。下载nginx:http://nginx.org/en/download.html
2.下载win sw:https://github.com/winsw/winsw/releases/tag/v2.11.0 ,下载.NET 4.0 版本,WinSW.NET4.exe。
3.解压nignx压缩包,并重命名文件夹为“nginx”。本例的nginx.exe完整路径为:D:\Soft\nginx\nginx.exe
4。将下载的WinSW.NET4.exe 复制进D:\Soft\nginx\。
5。在D:\Soft\nginx\新建一个名为“WinSW.NET4.xml”的XML文件,内容如下:
<service> <!--服务名称--> <id>nginxsvr</id> <!--显示名称--> <name>nginx-svr</name> <!--描述--> <description>自启动的 nginx</description> <!--windows服务安装日志--> <logpath>D:\Soft\nginx\log2</logpath> <logmode>roll</logmode> <depend></depend> <executable>D:\Soft\nginx\nginx.exe</executable> <stopexecutable>D:\Soft\nginx\nginx.exe -s stop</stopexecutable> </service>
XML的路径根据实际情况修改。
6.用命令安装并启动:
D:\Soft\nginx\WinSW.NET4.exe install
NET START nginxsvr
7.如果需要卸载 :
NET STOP nginxsvr
D:\Soft\nginx\WinSW.NET4.exe uninstall
可以保存为批处理,安装BAT:
echo "安装" D:\Soft\nginx\WinSW.NET4.exe install echo "启动名为nginxsvr的windows服务" NET START nginxsvr pause
卸载BAT:
echo "一定要先停止后卸载,否则电脑需要重启" echo "停止名为nginxsvr的windows服务" NET STOP nginxsvr D:\Soft\nginx\WinSW.NET4.exe uninstall pause
可运行 services.msc 来查看服务状态。