将nginx安装为windows服务

一、nginx版本:nginx-1.23.1;windows版本:win11,将nginx解压,要保证nginx的目录不含空格

二、下载winsw,下载地址为:https://repo.jenkins-ci.org/artifactory/releases/com/sun/winsw/winsw/

三、将winsw-2.9.0-bin.exe复制到nginx目录下,并重命名为nginx-service.exe

四、在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>C:\nginx\logs</logpath>
    <log mode="roll-by-size">
        <sizeThreshold>10240</sizeThreshold>
        <keepFiles>8</keepFiles>
    </log>
    <executable>C:\nginx\nginx.exe</executable>
    <startarguments>-p C:\nginx</startarguments>
    <stopexecutable>C:\nginx\nginx.exe</stopexecutable>
    <stoparguments>-p C:\nginx -s stop</stoparguments>
</service>

五、在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>

六、以管理员身份打开cmd,输入:nginx-service.exe install,执行完成后nginx就增加到windows服务中,服务名称为nginx

七、如果想删除nginx服务,在cmd窗口中执行:SC delete nginx

评论区 0