Windows安装nginx服务

时间:2021-08-08
本文章向大家介绍Windows安装nginx服务,主要包括Windows安装nginx服务使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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.xml

<?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命令是否以管理员身份打开的。

原文地址:https://www.cnblogs.com/telwanggs/p/15114584.html