如果Nginx每次使用都需要手动启动确实很麻烦,所以最好将其设置为Windows系统服务,开机自启动就行了。
1.下载并修改运行环境支持程序
1)、下载地址:http://ng-srvinst.attron.org/
2)、修改ng_srv.xml文件内容:
[html] view plaincopyprint?
- <service>
- <id>nginx</id>
- <name>nginx</name>
- <description>nginx</description>
- <executable>d:\www\nginx\nginx.exe</executable>
- <logpath>d:\www\logs\</logpath>
- <logmode>roll</logmode>
- <depend></depend>
- <startargument>-p d:\www\nginx</startargument>
- <stopargument>-p d:\www\nginx -s stop</stopargument>
- </service>
<service> <id>nginx</id> <name>nginx</name> <description>nginx</description> <executable>d:\www\nginx\nginx.exe</executable> <logpath>d:\www\logs\</logpath> <logmode>roll</logmode> <depend></depend> <startargument>-p d:\www\nginx</startargument> <stopargument>-p d:\www\nginx -s stop</stopargument> </service>
将上述文件的Nginx目录改为自己本机Nginx所在的目录。我的Nginx版本是1.6.0,修改后的文件如下:
[html] view plaincopyprint?
- <service>
- <id>nginx</id>
- <name>nginx</name>
- <description>nginx</description>
- <executable>D:\BALANCE_TOMCAT__NGINX\nginx-1.6.0\nginx.exe</executable>
- <logpath>D:\BALANCE_TOMCAT__NGINX\nginx-1.6.0\logs\</logpath>
- <logmode>roll</logmode>
- <depend></depend>
- <startargument>-p D:\BALANCE_TOMCAT__NGINX\nginx-1.6.0</startargument>
- <stopargument>-p D:\BALANCE_TOMCAT__NGINX\nginx-1.6.0 -s stop</stopargument>
- </service>
<service> <id>nginx</id> <name>nginx</name> <description>nginx</description> <executable>D:\BALANCE_TOMCAT__NGINX\nginx-1.6.0\nginx.exe</executable> <logpath>D:\BALANCE_TOMCAT__NGINX\nginx-1.6.0\logs\</logpath> <logmode>roll</logmode> <depend></depend> <startargument>-p D:\BALANCE_TOMCAT__NGINX\nginx-1.6.0</startargument> <stopargument>-p D:\BALANCE_TOMCAT__NGINX\nginx-1.6.0 -s stop</stopargument> </service>
注:如果未修改此文件就安装服务,服务无法启动。会出现如下错误:
2.安装程序设置为Windows服务操作
在下载文件中有read.me打开之内容如下:
[plain] view plaincopyprint?
- NG_SRV
- Installation for nginx server like a service.
- 1. Change in ng_srv.xml path for your nginx path.
- 2. Launch "ng_srvinst.bat install" for service installation.
- 3. For uninstall launch "ng_srvinst.bat remove".
- Thats all.
NG_SRV Installation for nginx server like a service. 1. Change in ng_srv.xml path for your nginx path. 2. Launch "ng_srvinst.bat install" for service installation. 3. For uninstall launch "ng_srvinst.bat remove". Thats all.
下载文件的目录结构如下:
将ng_srvinst.bat安装为系统服务,如下图:
安装完成后查看是否安装成功“计算机”->"管理"->"服务",你可以看到Nginx服务已经安装成功,如下图:
参考地址:http://blog.csdn.net/csfreebird/article/details/8751532
时间: 2024-10-11 04:03:52