解决 NGINX Unit 报错 address already in use 端口监听冲突修复
排查 向 NGINX Unit 提交配置修改报错 failed to apply new configuration: bind to address failed: Address already in use,分析 端口冲突排查与孤儿工作进程清理。
问题现象
通过 REST API 向 Unit 提交监听端口变更时返回 HTTP 400 错误:
{
"error": "Failed to apply new configuration: bind(\"0.0.0.0:80\") failed: Address already in use (98)"
}
触发根因
- 宿主机上已有传统 Nginx、Apache 或其他应用占用了 80 / 443 等目标端口;
- Unit 历史异常崩溃后残留的僵尸工作进程仍在监听文件描述符。
解决步骤
定位占用目标端口的进程
检查 80 端口占用详情:
sudo ss -tulpn | grep :80
若发现是传统 nginx 或 apache2 占用,将其停用或停用其自动启动:
sudo systemctl stop nginx
重新向控制 API 提交更新
再次发送配置载荷:
sudo curl -X PUT --data-binary @config.json --unix-socket /var/run/unit/control.unit.sock http://localhost/config/
验证确认
确认 Unit 响应:
API 返回 {"success": "Reconfiguration done."},监听成功绑定。


