nginx bind() 至 0.0.0.0:443 失败(48:地址已在使用中)

nginx bind() 至 0.0.0.0:443 失败(48:地址已在使用中)

我在 Mac OS 10.14.2 上安装了 Laravel Valet 2.1.6。

使用 brew 安装 nginx 1.15.8。

我重新启动了 Mac,但没有安装任何更新或新软件,现在所有example.test网站都出现 502 错误,/usr/local/var/log/nginx/error.log日志中显示以下内容:

2019/01/17 20:38:47 [warn] 31277#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:1
2019/01/17 20:38:47 [emerg] 31277#0: bind() to 0.0.0.0:443 failed (48: Address already in use)
2019/01/17 20:38:47 [emerg] 31277#0: bind() to 0.0.0.0:443 failed (48: Address already in use)
2019/01/17 20:38:47 [emerg] 31277#0: bind() to 0.0.0.0:443 failed (48: Address already in use)
2019/01/17 20:38:47 [emerg] 31277#0: bind() to 0.0.0.0:443 failed (48: Address already in use)
2019/01/17 20:38:47 [emerg] 31277#0: bind() to 0.0.0.0:443 failed (48: Address already in use)
2019/01/17 20:38:47 [emerg] 31277#0: still could not bind()

同时,我在/Users/Myself/.config/valet/Log/nginx-error.log日志中看到以下内容:

2019/01/17 20:41:34 [error] 32071#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: example.test, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/Users/Myself/.config/valet/valet.sock:", host: "example.test"

当我跑步时ps ax -o pid,ppid,%cpu,vsz,wchan,command|egrep '(nginx|PID)'我看到这个列表:

  PID  PPID  %CPU      VSZ WCHAN  COMMAND
32064     1   0.0  4306660 -      nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;
32065 32064   0.0  4333284 -      nginx: worker process
32066 32064   0.0  4332260 -      nginx: worker process
32067 32064   0.0  4333284 -      nginx: worker process
32068 32064   0.0  4333284 -      nginx: worker process
32069 32064   0.0  4326116 -      nginx: worker process
32070 32064   0.0  4316900 -      nginx: worker process
32071 32064   0.0  4368236 -      nginx: worker process
32072 32064   0.0  4331236 -      nginx: worker process
32073 32064   0.0  4326116 -      nginx: worker process
32074 32064   0.0  4340452 -      nginx: worker process
32075 32064   0.0  4333284 -      nginx: worker process
32076 32064   0.0  4334308 -      nginx: worker process
36815  1406   0.0  4268060 -      egrep (nginx|PID)

以下任何操作都无法解决问题:

  • sudo killall nginx
  • brew services restart nginx
  • brew services restart php
  • valet restart
  • 重启我的 Mac
  • valet uninstall && valet install然后valet park在相关目录

Apache 并未作为冲突服务运行。

我尝试做了sudo /usr/local/opt/nginx/bin/nginx -g 'daemon off;'并得到了这个:

nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:60 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:60 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:60 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:60 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:60 failed (48: Address already in use)
nginx: [emerg] still could not bind()

运行sudo lsof -i tcp:80产生:

COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
nginx   42220 root    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42221 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42222 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42223 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42224 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42225 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42226 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42227 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42228 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42229 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42230 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42231 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)
nginx   42232 Myself    7u  IPv4 0x7ac8eae7874ccb11      0t0  TCP *:http (LISTEN)

当我针对端口 443 运行该命令时,输出基本上相同。

此代客问题帖子建议valet domain test可能会修复它,但这没有帮助。

尝试重新安装 PHP,但没有成功:

  • brew 卸载 --force php
  • brew 清理
  • brew 安装 php
  • 代客卸载 && 代客安装

尝试删除所有 valet 配置/证书目录,再次卸载 valet,然后重新安装并重新停放我的项目目录。

尝试以 root 身份运行 nginx:

  • sudo brew services stop nginx
  • 确认端口 80 上没有运行任何程序,也没有 nginx 进程
  • sudo brew services start nginx

答案1

我猜测真正的原因是您在之前的安装中以 root 身份运行了 brew 服务。

sudo brew services restart nginx

最后,您将 LaunchAgent 放入 /Library/LaunchAgents 中,这会在启动时以 root 身份启动 nginx,从而为您提供 2 个实例。您可以在活动监视器中检查这一点。

进入/Library/LaunchAgents并删除有问题的代理,然后重新启动。

答案2

这是由 PHP 7.3 引起的。

我删除了 Xdebug 7.3 和 2.7.0beta1 以适应 7.3 版本。

然后我照做了,然后使用 为 7.2 安装了 2.6.1 版本的 Xdebug 。brew install [email protected]pecl

现在一切正常。

答案3

在活动监视器的网络选项卡中强制退出 nginx 进程解决了我的问题

相关内容