Windows安装nginx服务

https://www.cnblogs.com/zhi-leaf/p/6274290.html

 

1、测试版本

  nginx版本:nginx-1.10.2;windows版本:win10

2、下载winsw。

  当前最新版本为:winsw-2.0.1-bin.exe。下载地址:http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/2.0.1/winsw-2.0.1-bin.exe。

3、将winsw-2.0.1-bin.exe复制到nginx目录下(保证nginx的目录不含空格),并重命名为nginx-service.exe。

4、在nginx目录下新增文件nginx-service.xml。

复制代码
<?xml version="1.0" encoding="UTF-8" ?>
<service>
    <id>nginx</id>
    <name>nginx</name>
    <description>High Performance Nginx Service</description>
    <logpath>D:\nginx-1.10.2\logs</logpath>
    <log mode="roll-by-size">
        <sizeThreshold>10240</sizeThreshold>
        <keepFiles>8</keepFiles>
    </log>
    <executable>D:\nginx-1.10.2\nginx.exe</executable>
    <startarguments>-p D:\nginx-1.10.2</startarguments>
    <stopexecutable>D:\nginx-1.10.2\nginx.exe</stopexecutable>
    <stoparguments>-p D:\nginx-1.10.2 -s stop</stoparguments>
</service>
复制代码

5、在nginx目录下新增文件nginx-service.exe.config

复制代码
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v2.0.50727" />
        <supportedRuntime version="v4.0" />
    </startup>
    <runtime>
        <generatePublisherEvidence enabled="false" />
    </runtime>
</configuration>
复制代码

6、文件结构如下:

 

7、启用windows自带的.Net Framework服务。

8、使用管理员身份运行cmd。

  右键“C:\Windows\System32\cmd.exe”,选择“已管理员身份运行”。

9、运行命令:nginx-service.exe install。

执行完成后可以查看nginx服务

10、启动nginx,访问nginx成功。

11、卸载nginx服务,在cmd命令窗口下执行:nginx-service.exe uninstall。

 

提示:1、若出现“WMI.WmiException: AccessDenied”错误,请检测cmd命令是否以管理员身份打开的。

posted on 2021-12-30 16:56  四海骄阳  阅读(1050)  评论(0编辑  收藏  举报

导航