# APIGetway ## 部署为 Windows 服务 在项目目录执行以下命令,发布适用于 64 位 Windows 的独立程序(目标机器无需安装 .NET 运行时): ```powershell dotnet publish .\APIGetway.csproj -c Release -r win-x64 --self-contained true -o .\publish ``` 将发布目录复制到服务器的固定位置,例如 `C:\Services\APIGetway`。在该目录的 `appsettings.json` 中配置 `ReverseProxy` 后端地址,以及服务监听地址。例如,添加以下顶层配置以监听所有网卡的 8080 端口: ```json "Urls": "http://0.0.0.0:8080" ``` 请根据实际网络环境配置端口和防火墙。服务进程中的 `localhost` 指运行服务的机器。默认监听地址通常为 `http://localhost:5000`;开发环境的 launchSettings.json 不适用于 Windows 服务。 以管理员身份打开 PowerShell,执行: ```powershell sc.exe create APIGetway binPath= 'C:\Services\APIGetway\APIGetway.exe' start= auto sc.exe start APIGetway ``` 查看状态、停止和卸载服务: ```powershell sc.exe query APIGetway sc.exe stop APIGetway sc.exe delete APIGetway ``` 修改配置或更新程序后,先停止服务,再替换文件并重新启动。服务默认以 LocalSystem 运行;如需访问受限资源,请配置具有相应权限的服务账户。可在 Windows 事件查看器的“Windows 日志 → 应用程序”中查看服务日志。项目仍可使用 `dotnet run` 作为普通控制台应用运行。