laravel / valet

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

Valet secure does not work #208

Closed matthijs110 closed 6 years ago

matthijs110 commented 8 years ago
OS: macOS Sierra 10.12.1
Valet version: 1.1.22

Hello,

When I execute the command valet secure, a message says that the site has been secured with a fresh TLS certificate (as it should).

If I try to access (http and https) the website, it gives me a browser 404 (so Valet does not seem to run). If I unsecure the site however, it works fine.

What could be the problem? I tried to completely remove Valet (including ~/.valet). Still no luck :/

willvincent commented 8 years ago

I briefly experienced a similar issue going the other direction.. from secure to unsecure.. restarted valet and it was fine. Might be a caching issue with caddy perhaps?

matthijs110 commented 8 years ago

Restarting Valet does not work unfortunately. Only valet unsecure.

erikwestlund commented 8 years ago

also having this issue

sa7bi commented 7 years ago

I'm also having the same problem :(

ahmedash95 commented 7 years ago

+1 for this issue , can't figure it out. [ Valet 2 ]

skybluesofa commented 7 years ago

I found a gist by Adam Wathan about Troubleshooting Valet on Sierra that helped me with this issue:

  1. Connection refused to https://mysite.dev
  2. Checked the Caddy start log at /tmp/com.laravel.valetServer.err
  3. Found this error: open /Users/myusername/.valet/Log/access.log: no such file or directory
  4. Discovered that the /Users/myusername/.valet/Log directory did not exist.
  5. Created the directory
  6. Ran CLI: touch /Users/myusername/.valet/Log/access.log
  7. Ran CLI: valet restart
  8. Re-checked the site at https://mysite.dev. Success!
ahmedash95 commented 7 years ago

@skybluesofa thanks but It didn't work with me .. also valet crashed after run secure command and it won't start until I run valet unsecure then valet start again

adamwathan commented 7 years ago

@ahmedash95 did you have Nginx already installed before installing Valet?

Try valet stop && brew uninstall --forge nginx, then re-run valet install to make sure nginx is installed with the correct flags.

ahmedash95 commented 7 years ago

@adamwathan It works .. thanks

mitoop commented 7 years ago

When use valet secure,nginx needs ngx_http_v2_module.Try nginx -t you will get the info. In mac,valet stop && brew uninstall --forge nginx and brew install nginx --with-http2 now it works. the option --with-http2 activate the ngx_http_v2_module.

PS: Valet source

Nginx.php

function install() { $this->brew->ensureInstalled('nginx', ['--with-http2']); //see this line $this->installConfiguration(); $this->installServer(); $this->installNginxDirectory(); }

Brew.php

function ensureInstalled($formula, $options = [], $taps = []) { if (! $this->installed($formula)) { $this->installOrFail($formula, $options, $taps); } }

function installed($formula) { return in_array($formula, explode(PHP_EOL, $this->cli->runAsUser('brew list | grep '.$formula))); }

So,if you installed the nginx without http2 before valet,valet secure will not work;

azimidev commented 7 years ago

still not working

joshmanders commented 7 years ago

@hassanazimi can you show us your version, what error message you get, etc.?

azimidev commented 7 years ago

@joshmanders Unfortunately there isn't any error. Everything runs well but when I wanna secure a domain like valet secure domain everything stops working. All webpages "cannot resolve the address". I have to the remove rm -rf ~/.valet and then valet install then valet park and everything works again. Summary: I can't secure a domain.

joshmanders commented 7 years ago

Try going into the project directory and running valet secure without the domain and see if that works.

azimidev commented 7 years ago

@joshmanders Still the same.

voicecode-bv commented 7 years ago

Had the same problem and it turned out I needed to update to the latest version of Laravel Valet. I was using 2.0.3 and now updated to 2.0.4 which solved my problem.

Hope this helps!

azimidev commented 7 years ago

@blyleven well i'm using 2.0.4

bohraji commented 7 years ago

@blyleven this worked for me. Thnx!

daddydanielt commented 7 years ago

@adamwathan It works .. thanks

azimidev commented 7 years ago

Still valet secure stops everything from working and I can't figure out why. I'm sure it adds a certificate to ~/.valet directory but everything stops from working. I have to remove ~/.valet directory and install valet again. this issue is about valet securenot the valet itself.

KickDu commented 7 years ago

I confirm, hassanazimi: I get the same issue - even with the above solutions

adamwathan commented 7 years ago

Can't replicate this, working as expected here.

Can you guys provide any more info about what isn't working? Is PHP running? Is nginx running? Is dnsmasq running? What do the log files say in PHP and nginx?

azimidev commented 7 years ago

@adamwathan Like I said when I install valet it works, which means php Nginx work as well but when I want to add or secure a domain, I can't access to the laravel dev domains whatsoever, even the ones I didn't want to be secured. Php and nginx do work though. The only thing I have to do is to remove ~/.valet directory and install valet again. Can't secure any domains locally.

adamwathan commented 7 years ago

Are PHP and nginx running after you run valet secure though? And what do the log files for nginx and PHP say after running that command?

Does ps aux | grep php list several php-fpm instances as running, like below?

image

Depending on if you are running 7.0 or 7.1, you'll find the FPM log in one of these locations:

/usr/local/opt/php70/var/log/php-fpm.log
/usr/local/opt/php71/var/log/php-fpm.log

...and the nginx log will be here:

~/.valet/Log/nginx-error.log

After running valet secure, what happens when you run:

sudo nginx -t

Does nginx -V list that it was compiled --with-http_v2_module or does that not show up?

KickDu commented 7 years ago

php is running and sudo nginx -t provides nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful so strange, for: /usr/local/opt/php70/var/log/php-fpm.log /usr/local/opt/php71/var/log/php-fpm.log there is not directory for php70 and php71 gives an empty log - normal ?!? ~/.valet/Log/nginx-error.log is empty too => ?!?

azimidev commented 7 years ago

@adamwathan

  1. These files are empty (no issues there)
/usr/local/opt/php71/var/log/php-fpm.log
~/.valet/Log/nginx-error.log

screen shot 2017-07-28 at 15 01 30

  1. ps aux | grep php returns as follows: (no issues there)

screen shot 2017-07-28 at 15 01 08

  1. BUT when I run sudo nginx -t this is what it returns:
nginx: [emerg] BIO_new_file("/Users/hasan_azimi0/.valet/Certificates/persianwoo.dev.crt") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/Users/hasan_azimi0/.valet/Certificates/persianwoo.dev.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed

screen shot 2017-07-28 at 15 02 01

Any clue Adam? I guess is permission problem but wondering how to fix.

adamwathan commented 7 years ago

Sounds like a certificate file didn't get generated or somehow got deleted.

Try running the following which will force Valet to regenerate all certs:

valet domain blah
valet domain dev
azimidev commented 7 years ago

Thanks Adam but still no luck.

adamwathan commented 7 years ago

Try deleting the contents of ~/.valet/Certificates and ~/.valet/Nginx and then restarting valet.

azimidev commented 7 years ago

When I try delete the content of both folders the site runs again but its not secure.

adamwathan commented 7 years ago

Ok so now what happens if you try to secure it again from scratch, now that things are working...?

adamwathan commented 7 years ago

Ok so now what happens if you try to secure it again from scratch, now that things are working...?

azimidev commented 7 years ago

I can see the it generates certificates in Certificates directory and one file in Nginx directory and when i open the browser This site can’t be reached and when i delete the files and valet restart it comes back again.

adamwathan commented 7 years ago

So when nginx is complaining about the file that doesn't exist, does it exist? Is there a difference in the file name nginx is looking for vs. the one you actually see in the certificates folder?

azimidev commented 7 years ago

It's the same, have a look:

screen shot 2017-07-28 at 19 38 47

I think it tries to read but somehow can't.

adamwathan commented 7 years ago

Can you screenshot running ls -la inside of the Nginx folder?

azimidev commented 7 years ago

Sure:

screen shot 2017-07-28 at 19 42 27

adamwathan commented 7 years ago

So actually the .crt file doesn't exist in the certificates directory which must be causing the issue. Probably something is failing during the secure stuff when trying to create the certificate.

The best I can recommend to help debug is trying to run all the steps you see in the code here manually in your terminal, and seeing if you get any errors:

https://github.com/laravel/valet/blob/master/cli/Valet/Site.php#L200-L267

uicosp commented 7 years ago

https://github.com/laravel/valet/blob/master/cli/Valet/Site.php#L239

just change /C=/ST=/O=/localityName=/commonName=*.%s/organizationalUnitName=/emailAddress=/ to /commonName=*.%s/ solved the problem

azimidev commented 7 years ago

@uicosp it DID actually fix it.

Thanks

agraynel commented 6 years ago

I have tried everything including delete .~/valet folder and reinstall everything, but I cannot start the website. I used to start it successfully. But after I updated homebrew, I can't open the website anymore. Any help?

joshmanders commented 6 years ago

probably getting php errors, you'll have to brew list and see if you still have php71 packages installed. If so uninstall them and reinstall php@7.1 as they renamed the formula

mohsin commented 6 years ago

I tried @mitoop solution to remove nginx and re-install with the --with-http2 flag. That didn't work as it gave me an unknown flag warning during the install (in the console logs) and continued to install nginx which failed to fix the bug.

I then checked the available flags using brew options nginx to see there was no —with-http2 flag. So I did a brew uninstall nginx and then did a brew install nginx-full --with-http2 (this had the necessary flag and you can check using brew options nginx-full). Once installed, I did a valet install, cd’ed into the project folder and did a valet secure and valet open. The bug was fixed and my project opened properly with https.

azimidev commented 6 years ago

@SaifurRahmanMohsin thats great to know. thanks for taking the time to update this. What's the difference with nginx vs. nginx-full anyway?

josegus commented 4 years ago

not working, tried everything

drbyte commented 4 years ago

not working, tried everything

Please open a new issue, and include the output from valet diagnose

alexiovay commented 1 year ago

The only command that worked for me was sudo nginx -s stop && sudo nginx