1.安装Nginx
1.1 下载windows版nginx (http://nginx.org/download/nginx-1.10.0.zip),解压到需要放置的位置(D:\xampp\nginx)
1.2 安装nginx
2.将Nginx设置为Windows服务
需要借助"Windows Service Wrapper"小工具,项目地址: GitHub - winsw/winsw: A wrapper executable that can run any executable as a Windows service, in a permissive license.
下载地址: http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/1.18/winsw-1.18-bin.exe
下载该工具后,将其放在 Nginx安装目录下,重命名为nginx-service.exe,创建配置文件nginx-service.xml(名字要和工具名一样),
创建nginx-service.exe.config(为支持NET 4.0 runtime,默认只支持NET 2.0 runtime)
2.1 文件结构如下:
2.2 nginx-service.xml 内容如下:
<service>
<id>nginx</id>
<name>Nginx Service</name>
<description>High Performance Nginx Service</description>
<logpath>D:\xampp\nginx\logs</logpath>
<log mode="roll-by-size">
<sizeThreshold>10240</sizeThreshold>
<keepFiles>8</keepFiles>
</log>
<executable>D:\xampp\nginx\nginx.exe</executable>
<startarguments>-p D:\xampp\nginx</startarguments>
<stopexecutable>D:\xampp\nginx\nginx.exe</stopexecutable>
<stoparguments>-p D:\xampp\nginx -s stop</stoparguments>
</service>
2.3 nginx-service.exe.config 内容如下:
<configuration>
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0" />
</startup>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
</configuration>
2.4 以管理员身份运行 cmd,运行如下命令安装windows服务
D:\xampp\nginx\nginx-service.exe install
2.5 Windows服务面板中启动服务了
2.6 浏览器中正常访问
常见问题解决方案
1.出现如下错误时:注意NGINX--SERVICE.XML扩展名必须为xml