1

I have Laravel Valet 2.1.6 installed on Mac OS 10.14.2.

nginx 1.15.8 is installed using brew.

I restarted my Mac without installing any updates or new software, and now all example.test sites are giving a 502 error with the following showing in the /usr/local/var/log/nginx/error.log 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()

At the same time, I get the following in the /Users/Myself/.config/valet/Log/nginx-error.log 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"

When I run ps ax -o pid,ppid,%cpu,vsz,wchan,command|egrep '(nginx|PID)' I see this list:

  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)

None of the following solves the issue:

  • sudo killall nginx
  • brew services restart nginx
  • brew services restart php
  • valet restart
  • Restarting my Mac
  • valet uninstall && valet install then valet park on the relevant dir

Apache is not running as a conflicting service.

I tried doing sudo /usr/local/opt/nginx/bin/nginx -g 'daemon off;' and got this:

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()

Running sudo lsof -i tcp:80 produces:

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)

Basically the same output when I run that command for port 443.

This valet issue post suggests valet domain test might fix it, but that didn't help.

Tried reinstalling PHP but no luck:

  • brew uninstall --force php
  • brew cleanup
  • brew install php
  • valet uninstall && valet install

Tried deleting all valet config/certificate directories, uninstalled valet again, then reinstalled and re-parked my project dir.

Tried running nginx as root:

  • sudo brew services stop nginx
  • Confirmed nothing is running on port 80 and no nginx processes
  • sudo brew services start nginx
eComEvo
  • 1,011
  • 3
  • 20
  • 32
  • 1
    You should first kill the existing nginx processes, **make sure they are actually dead** and only then restart nginx. – Michael Hampton Jan 18 '19 at 22:13
  • Already did that with `sudo killall nginx` and with `sudo brew services stop nginx`. Confirmed nothing running on port 80 or under nginx before starting again. – eComEvo Jan 22 '19 at 01:47
  • @eComEvo Your error messages indicate port **443** is the issue, so checking that nothing's running on port **80** won't do you much good. – ceejayoz Jan 22 '19 at 01:59
  • I checked 443 and the only thing listening on port 443 is nginx. Nothing is listening there after I stop all those processes and start nginx fresh as root. Uninstalling valet, deleting all valet configs, then reinstalling has finally gotten rid of the `Address already in use` error. However, every page load still shows this in the log: `[error] 78364#0: *4 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"` – eComEvo Jan 22 '19 at 02:17
  • Possible duplicate of [nginx error\_log reports “bind() to 0.0.0.0:80 failed (48: Address already in use)”](https://serverfault.com/questions/548740/nginx-error-log-reports-bind-to-0-0-0-080-failed-48-address-already-in-use) – Thomas Jan 26 '19 at 09:40

3 Answers3

2

I'm guessing the real reason for this is that you ran the brew services as root in a prior installation.

sudo brew services restart nginx

And you ended up putting a LaunchAgent inside /Library/LaunchAgents and that is starting up nginx as root at startup giving you 2 instances. You can check for this in activity monitor.

Go into /Library/LaunchAgents and remove the offending Agent, and restart.

Gazzer
  • 185
  • 1
  • 2
  • 9
0

This was caused by PHP 7.3.

I removed 7.3 and 2.7.0beta1 of Xdebug for 7.3.

I then did brew install php@7.2, then installed the 2.6.1 version of Xdebug for 7.2 using pecl.

Everything works fine now.

eComEvo
  • 1,011
  • 3
  • 20
  • 32
-1

Force quitting nginx processes in network tab of Activity Monitor fixed my issue

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300