一、windows系统下Nginx安装启动流程:
1、下载安装
到nginx官网下载相应版本(http://nginx.org/en/download.html),下载完成后直接解压就可以了
2、使用
启动Nginx,两种方法:
第一种是直接双击nginx.exe,会看到一个黑色的弹窗一闪而过,启动完成。
第二种是打开cmd命令窗口,切换到nginx目录下,输入命令 nginx.exe 或者 start nginx ,回车即可。
3、检查
检查nginx是否启动成功。
直接在浏览器地址栏输入网址 http://localhost:80,回车,出现以下页面说明启动成功。
二、将Nginx注册成服务,设置Nginx开机自动启动
1、下载小工具
下载地址:https://github.com/winsw/winsw/releases
2、注册服务
下载后将该工具放入Nginx的安装目录下,并且将其重命名为 nginx-service.exe
;
在nginx安装目录下新建服务日志文件夹server-logs文件夹,用来存放nginx服务相关日志。
在该目录下新建 nginx-service.xml 文件,写入配置信息,配置好了之后就可以通过这个将Nginx注册为Windows服务了。
<!-- nginx-service.xml -->
<service>
<id>nginx</id>
<name>nginx</name>
<description>nginx</description>
<env name="HOME" value="%BASE%"/>
<logpath>%BASE%\server-logs</logpath>
<log mode="roll-by-size-time">
<sizeThreshold>10240</sizeThreshold>
<pattern>yyyyMMdd</pattern>
<autoRollAtTime>00:00:00</autoRollAtTime>
<zipOlderThanNumDays>5</zipOlderThanNumDays>
<zipDateFormat>yyyyMMdd</zipDateFormat>
</log>
<executable>%BASE%\nginx.exe</executable>
<stopexecutable>%BASE%\nginx.exe -s stop</stopexecutable>
</service>
在nginx安装目录下以管理员运行命令:.\nginx-service.exe install
完成注册
启动对应的服务 nginx-service.exe start,完成开机自启
三、相关命令
注册系统服务命令 |
nginx-service.exe install |
删除已注册的系统服务命令 |
nginx-service.exe uninstall |
停止对应的系统服务命令 |
nginx-service.exe stop |
启动对应的系统服务命令 |
nginx-service.exe start |