laravel / valet

A more enjoyable local development experience for Mac.
https://laravel.com/docs/valet
MIT License
2.5k stars 691 forks source link

502 Bad Gateway - nginx/1.10.2 #269

Closed rsm23 closed 6 years ago

rsm23 commented 7 years ago

I'm using Laravel Valet 2.0.3 on MacOS Sierra And I'm getting this error everytime I restart my laptop

screen shot 2016-12-17 at 10 41 41 am

adamwathan commented 7 years ago

Did you run valet install after upgrading? On Sat, Dec 17, 2016 at 4:42 AM Saif Lacrimosa notifications@github.com wrote:

I'm using Laravel Valet 2.0.3 on MacOS Sierra And I'm getting this error everytime I restart my laptop

[image: screen shot 2016-12-17 at 10 41 41 am] https://cloud.githubusercontent.com/assets/2084708/21285893/8326b55e-c445-11e6-889c-ac72d29859ec.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/laravel/valet/issues/269, or mute the thread https://github.com/notifications/unsubscribe-auth/AEH3bLhYFkJk1PT8_hYpm22zfNu_cBQ2ks5rI66agaJpZM4LP2JJ .

rsm23 commented 7 years ago

Yes of course

ekandreas commented 7 years ago

Same here...

rsm23 commented 7 years ago

Isn't there any solution for that?

mpociot commented 7 years ago

Same for me - I encountered this issue only after updating to Sierra 10.12.2 (16C67).

ekandreas commented 7 years ago

So, I did work around this by two actions:

  1. Reinstall with the http2 parameter.
  2. Adjust fastcgi buffer settings in valet.conf.

Take a look at some similar issues in this repo!

mpociot commented 7 years ago

That's not working for me. I don't always get a 502 Bad Gateway, I get it 2-3 requests on my .dev sites if I keep refreshing.

So it also happens for static files.

My nginx-error.log file is full of these messages:

2016/12/23 11:41:51 [error] 50831#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/marcel/.valet/valet.sock:", host: "botman-docs.dev"
hsleewis commented 7 years ago

Also still an issue here,.. anyone has a working solution?

adamwathan commented 7 years ago

I haven't been able to reproduce this at all but some things online point to it maybe having something to do with large responses and big files. Is anyone able to create some sort of repository or something that demonstrates this in a reproducible way?

hsleewis commented 7 years ago

I have a couple of pages where I do a number of external requests, it looks like I get the error on those pages. Unfortunately nothing I can make available publicly. I even reinstalled my new MacBook Pro on a new partition and tested it, but I get exactly the same issues.

simonpeters commented 7 years ago

Having the same issue since updating to 2.0.3

drbyte commented 7 years ago

What's recorded in your ~/.valet/Log/nginx-error.log ?

simonpeters commented 7 years ago

It's an empty file

In error.log I have this though

06/Jan/2017:20:18:47 +0100 [ERROR 502 /server.php] dial tcp 127.0.0.1:9000: getsockopt: connection refused

edit: Rebooting fixed it for me, I think some old service was still running and it was breaking the nginx.

drbyte commented 7 years ago

Ya, that was gonna be my next comment:

502 Bad Gateway often means that the call to php-fpm is failing ... usually because it hasn't started properly, or the nginx config is pointing to a php-fpm config that's incorrect.

Common configurations for calling php-fpm are:

On a fresh install of valet, or a fresh upgrade, usually just rebooting is enough, since other services might have been hanging on those and preventing them from starting properly.

Often you can determine this by inspecting your ~/.valet/Log/nginx-error.log and /usr/local/var/log/php-fpm.log after running sudo brew services restart nginx && sudo brew services restart php71

Glad you got it working.

tlaverdure commented 7 years ago

@adamwathan I was getting this error just now when trying to perform a POST. In my ngnix-error.log I'm seeing this error:

 upstream sent too big header while reading response header from upstream

I was able to fix by adding these two lines to my valet.conf file in the location ~ \.php$ block:

fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;

I also tested this POST request with less form fields and it seems to be consistent with the amount of data being submitted.

Reference

GiamPy5 commented 7 years ago

I keep having the same issues.

fastcgi buffer settings did not fix the issue. rebooting did not fix the issue.

hsleewis commented 7 years ago

With my computer it always happens when doing a POST request.

jesusamezag commented 7 years ago

I've the same issue...

Here is my log:

2017/01/20 17:59:21 [crit] 14300#0: *196 connect() to unix:/Users/jesusarturomezageraldo/.valet/valet.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/jesusarturomezageraldo/.valet/valet.sock:", host: "foobar.dev" 2017/01/20 17:59:21 [crit] 14300#0: *196 connect() to unix:/Users/jesusarturomezageraldo/.valet/valet.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://unix:/Users/jesusarturomezageraldo/.valet/valet.sock:", host: "foobar.dev", referrer: "http://foobar.dev/"

jpmurray commented 7 years ago

I'm having the same log output as @jesusamezag here, but it all started to happen after I did valet unsecure on one of my site/folder...

jpmurray commented 7 years ago

I made a couple uninstall/install cycle and I wouldn't get valet started anymore. What got me back on track was stopping valet, uninstalling nginx and reinstalling it with brew install nginx --with-http2. Now all seems ok.

I don't think it could help for everyone, but in case it could... !

mrailton commented 7 years ago

Having same issues and have tried all the solutions in this thread. content from the error log is

2017/01/27 10:39:15 [crit] 41134#0: *7 connect() to unix:/Users/mark/.valet/valet.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/mark/.valet/valet.sock:", host: "personalsite.dev

Hoping someone else has a solution for this as currently means I'm back to using vagrant for local dev and would really rather use valet

Update

I've just managed to resolve this, appears a composer global update followed by valet install is all that was needed, hope that this helps someone else.

thinkstylestudio commented 7 years ago

I know when I was snooping I was unable to find /Users/mark/.valet/valet.sock It did not exist. I couldn't test if that was the issue either as I don't know what should in theory be in the file.

On January 27, 2017 at 2:42:47 AM, Mark Railton (notifications@github.com) wrote:

Having same issues and have tried all the solutions in this thread. content from the error log is

2017/01/27 10:39:15 [crit] 41134#0: *7 connect() to unix:/Users/mark/.valet/valet.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/mark/.valet/valet.sock:", host: "personalsite.dev

Hoping someone else has a solution for this as currently means I'm back to using vagrant for local dev and would really rather use valet

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/laravel/valet/issues/269#issuecomment-275637515, or mute the thread https://github.com/notifications/unsubscribe-auth/AATrQANdpUWXZa-FO0OqmXCaj5G1IsbDks5rWcongaJpZM4LP2JJ .

drbyte commented 7 years ago

The valet.sock file has no content. In some ways it's not really even a "file". It's a socket. But it shows up as a file on the filesystem.

The ~/.valet/valet.sock file is created upon PHP startup, and removed on normal shutdown.

If it doesn't exist then PHP didn't/couldn't start properly. Look at the /usr/local/var/log/php-fpm.log for messages.

xboston commented 7 years ago

Hi @rsm23!

Check please:

$ ls -lm $HOME/.valet
Certificates, Drivers, Extensions, Log, Nginx, Sites, config.json, dnsmasq.conf

$ brew services start php71
==> Successfully started `php71` (label: homebrew.mxcl.php71)

$ ls -lm $HOME/.valet
Certificates, Drivers, Extensions, Log, Nginx, Sites, config.json, dnsmasq.conf, valet.sock

Done.

thomas-oo commented 7 years ago

@xboston

I'm not seeing valet.sock after I run brew services start php71. After I start php71 and I check brew services list, it is started.

drbyte commented 7 years ago

Have you tried sudo instead?

thomas-oo commented 7 years ago

yes now I see valet.sock and my issue is no long a 502 error but now I have a 404 error, valet - not found... and yes I've valet park'ed the directory above the valet project I've created

edit: nvm I'm dumb I had another domain (not .dev) for valet domain and forgot.

tatocaster commented 7 years ago

after upgrading to 2.XX i have the same problem. usr/local/var/log/php-fpm.log is empty, nginx-error.log says .valet/valet.sock failed (2: No such file or directory)

tatocaster commented 7 years ago

sudo brew services restart nginx && sudo brew services restart php71 if it writes that permissions are messed up , use this link below. StackOverflow

everything is up and running.

bobbypiper commented 7 years ago

@tatocaster thanks - that has put it right for me seems the nginx/1.10.3/homebrew.mxcl.nginx.plist had permission issues - that SO post helped

Davidsr commented 7 years ago

Hi, I have a 404 error. What you think about this?:

sudo chown root /Library/LaunchDaemons/myfile.plist
sudo chgrp wheel /Library/LaunchDaemons/myfile.plist

Done

nginx -t

nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:1
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/usr/local/var/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed
pryley commented 7 years ago

I was having the same problem. In my case it happened after brewing a new PHP version and trying to switch to it:

  1. brew install php71
  2. valet install

At this point everything works.

  1. brew install php70
  2. sudo brew services stop php71
  3. brew unlink php71
  4. brew link php70
  5. sudo brew services start php70

Now I get the following 502 Bad Gateway error when loading a site:

2017/02/07 21:13:23 [crit] 78452#0: *1 connect() to unix:/Users/me/.valet/valet.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/me/.valet/valet.sock:", host: "laravel.dev"

To fix this, you have to run valet install after brewing a new PHP version.

  1. valet install

Now running steps 4-7 to swap between PHP versions works correctly. 🍻

Davidsr commented 7 years ago

Ok, the solution for my problem 404 error was.

valet link valet start

I don´t know why valet park is not working.

swiftliuziyang commented 7 years ago

when i input $ sudo brew services start php70 in my mac's command line, it works! thank for pryley

rchoffardet commented 7 years ago

sudo brew services start php70 also fixed my issue. But, i think it only fixes the symptom and not the real problem... i would love to have a real fix.

I continue my researches :smile:

Update

I really don't get why it doesn't work, in the code we have this :

    function restartService($services)
    {
        $services = is_array($services) ? $services : func_get_args();

        foreach ($services as $service) {
            $this->cli->quietly('sudo brew services restart '.$service);
        }
    }

So the only difference is restart instead of start how can it be that different ?

cerw commented 7 years ago

Try to run /usr/local/opt/php70/sbin/php70-fpm configtest and see if php-fpm it self is OK in my case it was bad permission, like sudo brew .. will mark it as root :(

After i fixed it, it work now!

rchoffardet commented 7 years ago

Seems like it worked ! But I said just above, the only difference in the two commands was start or restart which is kinda weird..

joelpierre commented 7 years ago

So my fix was as so even though I have brew linked php71:

1) sudo brew services start php70 2) valet start

It works. But again I have php71 linked so why did this work?

shahbaaz commented 7 years ago

Even if you stop and uninstall valet. Caddy server still runs in the background. To get rid of Caddy server, follow these instructions:

valet stop valet uninstall

Delete these executable files sudo rm /usr/local/bin/valet and sudo rm /Users/{home-directory}/.composer/vendor/bin/valet (replace {home-directory} with your home directory name)

Make sure Caddy server and valet is removed from your computer completely.

when you type valet in terminal. You should see: command not found: valet

when you type curl -I foo.dev. You should see: curl: (6) Could not resolve host: foo.dev

Now install valet following the instructions in documentation: https://laravel.com/docs/5.4/valet#installation

Still if it doesn’t work. Type these command in your terminal: brew services restart nginx && brew services restart php71

valet start or valet restart

ahmedchijai commented 7 years ago

sudo brew services start php71 it works! thank

jasperf commented 7 years ago

Another valet install on top of an existing older one did the trick to get back valet.sock . Here:

ls -lm $HOME/.valet
Caddy, Caddyfile, Certificates, Drivers, Extensions, Log, Nginx, Sites, config.json, dnsmasq.conf
Jaspers-MBP-2016:Log jasperfrumau$ valet install
Valet installed successfully!
Jaspers-MBP-2016:Log jasperfrumau$ ls -lm $HOME/.valet
Caddy, Caddyfile, Certificates, Drivers, Extensions, Log, Nginx, Sites, config.json, dnsmasq.conf, valet.sock

Afterwards the error 502 bad gateway disappeared and all my Laravel Valet sites started working again.

benleivian commented 7 years ago

Was having a similar issue, then I realized I had a vpn firewall active 😑

BobbyBorisov commented 7 years ago

I was having the same issue and installing php71 helped me

jartaud commented 7 years ago

@tatocaster thanks. Your solution works for me so i don't have to issue valet install command.

myalias='sudo service nginx restart && sudo service php7.0-fpm restart'

Ubuntu 16.04.2 LTS

llaski commented 7 years ago

For php56 I had to manually change the listen value in the php-fpm.conf file (Something like listen = '.VALET_HOME_PATH.'/valet.sock). Normally it gets replaced by valet but didn't in my case. Hope this helps someone.

clarkeash commented 6 years ago

Ive had this issue today on High Sierra and ultimately fixed it (after lots of googling)

brew uninstall php71
brew prune
rm -rf /usr/local/opt/php71
brew install php71 php71-xdebug
sudo valet install
ctf0 commented 6 years ago

@tlaverdure where to add the config ? i cant find valet.conf anywhere except in cli/stubs

update found it, /usr/local/etc/nginx/valet/valet.conf

mikezange commented 6 years ago

@clarkeash Fixed issue for me, thanks!

brew uninstall php71
brew prune
rm -rf /usr/local/opt/php71
brew install php71 php71-xdebug
sudo valet install
adamnator92 commented 6 years ago

solved my permissions problem by valet install

llbbl commented 6 years ago

Hey everyone. The solution this is to that nginx can't pass requests to php-fpm. This is normally because php-fpm listener is not configured correctly. PHP can be configured to respond to request via unix socket or via TCP socket.

Check where your www.conf file is configured to listen:

listen = /run/php/php7.0-fpm.sock
or
listen = 127.0.0.1:9000
or what valet wants... 
listen = /Users/YourUserName/.valet/valet.sock

Hope this helps someone else. Just finished double clawing myself outta that hole.

The config files you care about are here:

/usr/local/etc/php/7.2/php-fpm.d/www.conf
~/valet/Nginx/sitename

The nginx conf file will only show up if you do a valet secure, otherwise not sure where it is.