Closed diegovogel closed 1 year ago
I tried just about all the solutions in this thread but they didn't help: #717
I think the problem there was a bit different. They were having problems with all sites, I'm only having problems when trying to use valet proxy
but otherwise valet serves sites just fine.
When you said that valet proxies
doesn't list it, that's the first area for concern.
When you ran the valet proxy l8c http://127.0.0.1:9200
command it should have created an nginx config file for the domain:
/Users/diego/.config/valet/Nginx/l8c.off
And when you tried to visit the domain, if that proxy config file was running in Nginx but an Nginx error occurred, then the details of the 502 error would be contained in another file:
/Users/diego/.config/valet/Log/l8c.off-error.log
If the nginx site config file for the proxied domain didn't get created, then sorting that out will be what needs investigation.
If that's because of filesystem permissions, then one way to check is:
If you've got secured
sites created, they should be in your /Users/diego/.config/valet/Nginx/
directory. (They're created/deleted when running valet secure/unsecure
commands). If there's a filesystem permission problem preventing creating the proxy config in that directory, then running secure/unsecure probably also fails for non-proxy sites as well.
@drbyte thanks for your help. The nginx config file is being created as expected. Here are the contents:
# valet stub: secure.proxy.valet.conf
server {
listen 127.0.0.1:80;
#listen 127.0.0.1:80; # valet loopback
server_name l8c.off www.l8c.off *.l8c.off;
return 301 https://$host$request_uri;
}
server {
listen 127.0.0.1:443 ssl http2;
#listen 127.0.0.1:443 ssl http2; # valet loopback
server_name l8c.off www.l8c.off *.l8c.off;
root /;
charset utf-8;
client_max_body_size 128M;
http2_push_preload on;
location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
internal;
alias /;
try_files $uri $uri/;
}
ssl_certificate "/Users/diego/.config/valet/Certificates/l8c.off.crt";
ssl_certificate_key "/Users/diego/.config/valet/Certificates/l8c.off.key";
access_log off;
error_log "/Users/diego/.config/valet/Log/l8c.off-error.log";
error_page 404 "/Users/diego/.composer/vendor/laravel/valet/server.php";
location / {
proxy_pass http://127.0.0.1:9200;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Client-Verify SUCCESS;
proxy_set_header X-Client-DN $ssl_client_s_dn;
proxy_set_header X-SSL-Subject $ssl_client_s_dn;
proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
chunked_transfer_encoding on;
proxy_redirect off;
proxy_buffering off;
}
location ~ /\.ht {
deny all;
}
}
When I try to view the site, this is what gets logged to l8c.off-error.log
:
2023/04/28 16:08:53 [error] 41487#0: *9 kevent() reported that connect() failed (61: Connection refused) while connecting to upstream, client: 127.0.0.1, server: l8c.off, request: "GET / HTTP/2.0", upstream: "http://127.0.0.1:9200/", host: "l8c.off"
Any idea what that might mean?
Since first reporting this issue I installed PHP Monitor and the proxy is detected there even though valet isn't listing it.
(61: Connection refused) while connecting to upstream
usually means the listening service isn't running. ie: whatever you're supposed to be running on port 9200 at 127.0.0.1.
I'm not sure why your valet proxies
isn't showing it.
I copied the contents that you posted, into my own /Users/me/.config/valet/Nginx/l8c.test
(.test because that's my valet tld, instead of .off in your case), and when I run valet proxies
it shows it:
+---------+-----+---------------------+-----------------------+
| Site | SSL | URL | Host |
+---------+-----+---------------------+-----------------------+
| l8c | | http://l8c.test | http://127.0.0.1:9200 |
| mailhog | | http://mailhog.test | http://localhost:8025 |
+---------+-----+---------------------+-----------------------+
(Mine doesn't show SSL because i didn't generate certificates for it. I was only testing that the proxies
command would recognize the file properly)
Of course it works fine there 😅 PHP Monitor was showing PHP in an error state. The logs indicated there multiple instances of php-fpm running. Uninstalled/reinstalled PHP via homebrew and that fixed the error. But still no luck with the proxy.
Another weird thing is that if I remove the l8c.off
link entirely (valet unlink
), then run valet proxy...
without linking it, it's listed by valet proxies
. But if I link it and then proxy it it's not listed.
Going back to the nginx error -- after setting up the proxy, is there something else I have to do in order to start the listening service or run the site at 127.0.0.1:9200
(not even sure the right terminology here, way out of my depth).
Yes, if the site is "linked" then it won't be listed as a proxy, because valet only recognizes "link OR proxy" for any given "name".
How specifically do you want to run your WP sites vs Laravel sites? WP on port 80 and Laravel on ... what?
Valet should detect WP as different from Laravel. Is there a specific WP problem that valet isn't capable of handling for you?
Yes sorry, the problem is that I use Local to serve WP and Valet for Laravel. They both use port 80 by default so they conflict. What I've been doing whenever I switch between WP and Laravel is quit Local or stop Valet. It's just annoying because I often switch multiple times a day. Local has a way to get around port conflicts but it means no https and no custom domains (not the end of the world). I was hoping to use valet proxy
to serve all my Laravel apps on a different port so they stop conflicting with Local. The port number doesn't matter to me, I was just using 9200 because that's what was in the Valet docs.
Thanks for explaining that sites can only be linked or proxied. I didn't get that from the docs or missed it. So now valet proxy
is working as far as recognizing the proxy (it's listed by valet proxies
). I'm still getting a 502 error, but I'll try clearing all the caches I can think of 😆
@drbyte clearing caches and rebooting didn't help. However if I serve the site with php artisan serve --port=9200
then everything works. I can go to https://l8c.off
to view the site. So I guess the site just isn't being served at 127.0.0.1:9200
unless I explicitly do that. That seems like something Valet should do for me. Am I missing something or do I just have to run php artisan serve
every time?
Valet's whole configuration is based on using ports 80 and 443 as per standard http and https protocols.
To get it to run on another port in order to not conflict with something else running on those ports, you'll have to do some tinkering. Ports 81 and 444 could work.
(first, delete those proxied sites you created, using valet unproxy
, because they're irrelevant: you won't be proxying)
Run valet stop nginx
before making these edits.
You'll have to change 2 :80
references to :81
in these files:
/usr/local/etc/nginx/valet/valet.conf
~/.composer/vendor/laravel/valet/cli/stubs/site.valet.conf
And for valet secure
to correctly serve valet sites you'll need to edit 2 :80
(to 81) and 2 :443
(to 444) references in:
~/.composer/vendor/laravel/valet/cli/stubs/secure.valet.conf
Then you'll need to re-secure all the sites you've created with valet secure
.
(Tip: if you have a lot, you could just change your valet tld
to something else, and then back again, and it'll do them all in a batch.)
Run valet start nginx
for the edits to take effect.
CAVEATS:
laravel/valet/cli/stubs
files might get overwritten whenever you upgrade Valet to new versions, if those files have been changed as part of the upgrade. So you will need to re-do these edits.
The /usr/local/etc/nginx/valet/valet.conf
file will only get overwritten if you re-run valet install
.valet share
without more customizations to core php code.valet proxy
without updating the proxy stubs.(NOTE: This is the implementation in concept; unfortunately I'm unable to "do" this on my local machine right now to find any edge-case issues. I'm also uncertain what ripple-effect issues may result.)
Or you could just explore whatever small adjustments might be made to Valet's WP driver to accommodate limitations that LocalWP meets.
Thanks a lot for outlining that. While I'm sure it would work, I'll stick with Valet on the default ports. Not a fan of going that deep into server configs, ha. Local has a solution for port conflicts that seems to work well with some minor downsides, so I'll use that instead. I thought valet proxy
was meant for this scenario though. I guess I misunderstood the docs. If it's not for this, what is it for?
I really appreciate all your help on this! I definitely learned a lot and understand Valet better now.
valet proxy
is for linking a servername to a service that's not a webserver. mailhog
is a common example.
It can also be used for some other advanced networking configurations.
(You can read more in the original PR: https://github.com/laravel/valet/pull/913 )
Unfortunately you can't run 2 webservers on the same port at the same time, and webservers normally run on ports 80 and 443, hence the conflict you were encountering.
If you have more questions related to Valet and your situation, feel free to ask. If this issue is resolved for now, please click Close below, to help us with housekeeping.
Thanks again!
@diegovogel If you're interested in more reading about the original reason for adding the proxy
feature, see https://github.com/laravel/valet/pull/913
@drbyte thanks for the additional context. I guess I'm confused about the Docker example, which is the same example from the Valet docs. It says valet proxy
is helpful when Valet and Docker both want to use port 80. Isn't that the same situation I was in? Valet and Local WP both want to use port 80. I think Local WP even uses Docker behind the scenes, not that that really matters. This is probably me being ignorant but I thought that the example meant valet proxy
could be used to get Valet on a different port so port 80 was freed up for Docker.
I thought that the example meant
valet proxy
could be used to get Valet on a different port so port 80 was freed up for Docker.
No, it's the other way around: valet proxy
allows you to link to services running on other ports so they can be served thru valet.
If you can get LocalWP to run on another port, you can serve it through valet by using valet proxy
.
Ohhh that makes sense. Thanks for explaining. LocalWP can only use alternate ports in localhost mode (http://localhost:12345 instead of http://my-domain.local:12345) but I set up a proxy through Valet and it works!
but I set up a proxy through Valet and it works!
Yay!
Description
I work with both Laravel and WordPress sites. For WordPress I use Local, which binds to port 80. I'm trying to use
valet proxy
as outlined in the docs to serve Laravel sites over a different port, so I can run Laravel and WP sites at the same time. I'm not sure if there are additional steps I'm unaware of or if the proxy command just isn't working. After adding a proxy and runningvalet proxies
, nothing is listed, and I get a 502 error if I try to visit the site. I've already run the composer and brew update/upgrade commands and reinstalled valet.Steps To Reproduce
Starting point: I have a working Laravel app that I can access at http://l8c.off.
$ valet proxy l8c http://127.0.0.1:9200
$ valet proxies
No proxies are listed. And if I visit http://l8c.off I get a 502 error.Diagnosis
sw_vers
valet --version
cat ~/.config/valet/config.json
cat ~/.composer/composer.json
composer global diagnose
composer global outdated
ls -al /etc/sudoers.d/
brew config
brew services list
brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
brew outdated
brew tap
php -v
which -a php
php --ini
nginx -v
curl --version
php --ri curl
/opt/homebrew/bin/ngrok version
ls -al ~/.ngrok2
brew info nginx
brew info php
brew info openssl
openssl version -a
openssl ciphers
sudo nginx -t
which -a php-fpm
/opt/homebrew/opt/php/sbin/php-fpm -v
sudo /opt/homebrew/opt/php/sbin/php-fpm -y /opt/homebrew/etc/php/8.2/php-fpm.conf --test
ls -al ~/Library/LaunchAgents | grep homebrew
ls -al /Library/LaunchAgents | grep homebrew
ls -al /Library/LaunchDaemons | grep homebrew
ls -al /Library/LaunchDaemons | grep "com.laravel.valet."
ls -aln /etc/resolv.conf
cat /etc/resolv.conf
ifconfig lo0
sh -c 'echo "------\n/opt/homebrew/etc/nginx/valet/valet.conf\n---\n"; cat /opt/homebrew/etc/nginx/valet/valet.conf | grep -n "# valet loopback"; echo "\n------\n"'
sh -c 'for file in ~/.config/valet/dnsmasq.d/*; do echo "------\n~/.config/valet/dnsmasq.d/$(basename $file)\n---\n"; cat $file; echo "\n------\n"; done'
sh -c 'for file in ~/.config/valet/nginx/*; do echo "------\n~/.config/valet/nginx/$(basename $file)\n---\n"; cat $file | grep -n "# valet loopback"; echo "\n------\n"; done'