@@ -39,11 +39,11 @@ cd C:\nginx
3939New-Item -ItemType Directory -Path "C:\nginx\ssl" -Force
4040```
4141
42- 将证书文件复制到此目录:
43- - ` C:\nginx\ssl\app.abc.cloud.crt `
44- - ` C:\nginx\ssl\app.abc.cloud.key `
45- - ` C:\nginx\ssl\manage.abc.cloud.crt `
46- - ` C:\nginx\ssl\manage.abc.cloud.key `
42+ 将证书文件复制到此目录(证书文件可以是 .pem 或 .crt 格式) :
43+ - ` C:\nginx\ssl\app.abc.cloud.pem ` 或 ` . crt` (证书文件)
44+ - ` C:\nginx\ssl\app.abc.cloud.key ` (私钥文件)
45+ - ` C:\nginx\ssl\manage.abc.cloud.pem ` 或 ` . crt` (证书文件)
46+ - ` C:\nginx\ssl\manage.abc.cloud.key ` (私钥文件)
4747
4848## 三、Nginx 配置
4949
8989 listen 443 ssl;
9090 server_name app.abc.cloud;
9191
92- # SSL 证书配置
93- ssl_certificate ssl/app.abc.cloud.crt ;
94- ssl_certificate_key ssl/app.abc.cloud.key;
92+ # SSL 证书配置(注意:Windows 路径使用正斜杠)
93+ ssl_certificate C:/nginx/ ssl/app.abc.cloud.pem ;
94+ ssl_certificate_key C:/nginx/ ssl/app.abc.cloud.key;
9595
9696 # SSL 安全配置
9797 ssl_protocols TLSv1.2 TLSv1.3;
@@ -147,9 +147,9 @@ http {
147147 listen 443 ssl;
148148 server_name manage.abc.cloud;
149149
150- # SSL 证书配置
151- ssl_certificate ssl/manage.abc.cloud.crt ;
152- ssl_certificate_key ssl/manage.abc.cloud.key;
150+ # SSL 证书配置(注意:Windows 路径使用正斜杠)
151+ ssl_certificate C:/nginx/ ssl/manage.abc.cloud.pem ;
152+ ssl_certificate_key C:/nginx/ ssl/manage.abc.cloud.key;
153153
154154 # SSL 安全配置
155155 ssl_protocols TLSv1.2 TLSv1.3;
@@ -225,36 +225,51 @@ cd C:\nginx
225225
226226## 五、将 Nginx 安装为 Windows 服务
227227
228- 为了让 Nginx 开机自动启动,建议将其安装为 Windows 服务。
229-
230- ### 5.1 使用 NSSM(推荐)
231-
232- 1 . ** 下载 NSSM**
233- - 访问 [ https://nssm.cc/download ] ( https://nssm.cc/download )
234- - 下载并解压 NSSM
235-
236- 2 . ** 安装 Nginx 服务**
237- ``` powershell
238- # 假设 NSSM 解压到 C:\nssm
239- cd C:\nssm\win64
240- .\nssm.exe install NginxService "C:\nginx\nginx.exe"
228+ 为了让 Nginx 开机自动启动,建议将其安装为 Windows 服务。
229+
230+ ### 5.1 使用 WinSW(推荐)
231+
232+ 1 . ** 下载 WinSW**
233+ - 访问 [ https://github.com/winsw/winsw/releases ] ( https://github.com/winsw/winsw/releases )
234+ - 下载最新的 ` WinSW-x64.exe ` 文件
235+ - 将文件重命名为 ` NginxService.exe ` 并放到 ` C:\nginx ` 目录
236+
237+ 2 . ** 创建配置文件**
238+
239+ 在 ` C:\nginx ` 目录下创建 ` NginxService.xml ` 文件:
240+ ``` xml
241+ <service >
242+ <id >NginxService</id >
243+ <name >Nginx Reverse Proxy</name >
244+ <description >Nginx reverse proxy for DeliciousFood applications</description >
245+ <executable >C:\nginx\nginx.exe</executable >
246+ <startmode >Automatic</startmode >
247+ <logpath >C:\nginx\logs</logpath >
248+ <log mode =" roll-by-size" >
249+ <sizeThreshold >10240</sizeThreshold >
250+ <keepFiles >8</keepFiles >
251+ </log >
252+ <onfailure action =" restart" delay =" 10 sec" />
253+ <onfailure action =" restart" delay =" 20 sec" />
254+ <resetfailure >1 hour</resetfailure >
255+ <stopexecutable >C:\nginx\nginx.exe</stopexecutable >
256+ <stopargument >-s</stopargument >
257+ <stopargument >quit</stopargument >
258+ </service >
241259 ```
242260
243- 3 . ** 配置服务 **
261+ 3 . ** 安装服务 **
244262 ``` powershell
245- .\nssm.exe set NginxService AppDirectory "C:\nginx"
246- .\nssm.exe set NginxService DisplayName "Nginx Reverse Proxy"
247- .\nssm.exe set NginxService Description "Nginx reverse proxy for DeliciousFood applications"
248- .\nssm.exe set NginxService Start SERVICE_AUTO_START
263+ cd C:\nginx
264+ .\NginxService.exe install
249265 ```
250266
251- 4 . ** 启动服务 **
267+ 4 . ** 启动服务并验证 **
252268 ``` powershell
269+ # 启动服务
253270 Start-Service NginxService
254- ```
255-
256- 5 . ** 查看服务状态**
257- ``` powershell
271+
272+ # 查看服务状态
258273 Get-Service NginxService
259274 ```
260275
@@ -263,7 +278,7 @@ cd C:\nginx
263278- ** 启动服务** : ` Start-Service NginxService `
264279- ** 停止服务** : ` Stop-Service NginxService `
265280- ** 重启服务** : ` Restart-Service NginxService `
266- - ** 卸载服务** : ` C:\nssm\win64\nssm .exe remove NginxService confirm `
281+ - ** 卸载服务** : ` C:\nginx\NginxService .exe uninstall `
267282
268283## 六、IIS 和 ASP.NET Core 应用配置
269284
0 commit comments