laravel / valet

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

No proxies listed after running `valet proxy` #1406

Closed diegovogel closed 1 year ago

diegovogel commented 1 year ago

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 running valet 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
ProductName:       macOS
ProductVersion:     13.3.1
BuildVersion:       22E261
valet --version
Laravel Valet 4.0.2
cat ~/.config/valet/config.json
{
    "tld": "off",
    "paths": [
        "/Users/diego/.config/valet/Sites"
    ],
    "loopback": "127.0.0.1"
}
cat ~/.composer/composer.json
{
    "require": {
        "laravel/valet": "^4.0",
        "laravel/installer": "^4.5",
        "spatie/global-ray": "^1.0",
        "statamic/cli": "^2.5"
    }
}
composer global diagnose
Changed current directory to /Users/diego/.composer
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK git version 2.40.1
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com oauth access: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.5.5
PHP version: 8.2.5
PHP binary path: /opt/homebrew/Cellar/php/8.2.5/bin/php
OpenSSL version: OpenSSL 1.1.1t  7 Feb 2023
cURL version: 8.0.1 libz 1.2.11 ssl (SecureTransport) OpenSSL/1.1.1t
zip: extension present, unzip present, 7-Zip not available
composer global outdated
Changed current directory to /Users/diego/.composer
Info from https://repo.packagist.org: #StandWithUkraine

Direct dependencies required in composer.json:
Everything up to date

Transitive dependencies not required in composer.json:
Everything up to date
ls -al /etc/sudoers.d/
total 0
drwxr-xr-x   2 root  wheel    64 Apr  1 12:46 .
drwxr-xr-x  81 root  wheel  2592 Apr 28 10:13 ..
brew config
HOMEBREW_VERSION: 4.0.15
ORIGIN: https://github.com/Homebrew/brew
HEAD: 763c41f006ab9b44261e313b0aaa24a047431b06
Last commit: 4 days ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 17aa4a59969dc7ba12430a84b8b8723ea931a544
Core tap last commit: 9 weeks ago
Core tap branch: master
Core tap JSON: 28 Apr 14:44 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 14.0.3 build 1403
Git: 2.40.1 => /opt/homebrew/bin/git
Curl: 7.87.0 => /usr/bin/curl
macOS: 13.3.1-arm64
CLT: 14.3.0.0.1.1679647830
Xcode: N/A
Rosetta 2: false
brew services list
Name    Status User File
dnsmasq none            root 
mysql   none                 
nginx   none            root 
php     error  19968    root ~/Library/LaunchAgents/homebrew.mxcl.php.plist
brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
dnsmasq 2.89 2.86
mysql 8.0.32
nginx 1.21.6_1 1.23.2 1.23.4
openssl@1.1 1.1.1t
php 8.2.4 8.2.5
brew outdated

brew tap
homebrew/core
homebrew/services
shopify/shopify
php -v
PHP 8.2.5 (cli) (built: Apr 13 2023 17:59:46) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.5, Copyright (c), by Zend Technologies
which -a php
/opt/homebrew/bin/php
/opt/homebrew/bin/php
php --ini
Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.2
Loaded Configuration File:         /opt/homebrew/etc/php/8.2/php.ini
Scan for additional .ini files in: /opt/homebrew/etc/php/8.2/conf.d
Additional .ini files parsed:      /opt/homebrew/etc/php/8.2/conf.d/error_log.ini,
/opt/homebrew/etc/php/8.2/conf.d/ext-opcache.ini,
/opt/homebrew/etc/php/8.2/conf.d/php-memory-limits.ini
nginx -v
nginx version: nginx/1.23.4
curl --version
curl 7.87.0 (x86_64-apple-darwin22.0) libcurl/7.87.0 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.51.0
Release-Date: 2022-12-21
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL threadsafe UnixSockets
php --ri curl
curl

cURL support => enabled
cURL Information => 8.0.1
Age => 10
Features
AsynchDNS => Yes
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => Yes
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => Yes
SSL => Yes
SSPI => No
TLS-SRP => Yes
HTTP2 => Yes
GSSAPI => Yes
KERBEROS5 => Yes
UNIX_SOCKETS => Yes
PSL => No
HTTPS_PROXY => Yes
MULTI_SSL => Yes
BROTLI => Yes
ALTSVC => Yes
HTTP3 => No
UNICODE => No
ZSTD => Yes
HSTS => Yes
GSASL => No
Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtmp, rtmpe, rtmps, rtmpt, rtmpte, rtmpts, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host => aarch64-apple-darwin22.3.0
SSL Version => (SecureTransport) OpenSSL/1.1.1t
ZLib Version => 1.2.11
libSSH Version => libssh2/1.10.0

Directive => Local Value => Master Value
curl.cainfo => no value => no value
/opt/homebrew/bin/ngrok version
sudo: /opt/homebrew/bin/ngrok: command not found
ls -al ~/.ngrok2
ls: /Users/diego/.ngrok2: No such file or directory
brew info nginx
==> nginx: stable 1.23.4 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/opt/homebrew/Cellar/nginx/1.21.6_1 (23 files, 2.2MB)
  Built from source
/opt/homebrew/Cellar/nginx/1.23.2 (23 files, 2.2MB)
  Built from source
/opt/homebrew/Cellar/nginx/1.23.4 (26 files, 2.2MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-04-07 at 09:09:25
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@1.1, pcre2
==> Options
--HEAD
    Install HEAD version
==> Caveats
Docroot is: /opt/homebrew/var/www

The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

To restart nginx after an upgrade:
  brew services restart nginx
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/nginx/bin/nginx -g daemon off;
==> Analytics
install: 1,384 (30 days), 34,490 (90 days), 382,629 (365 days)
install-on-request: 1,386 (30 days), 34,448 (90 days), 382,006 (365 days)
build-error: 2 (30 days)
brew info php
==> php: stable 8.2.5 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
/opt/homebrew/Cellar/php/8.2.4 (516 files, 83.3MB)
  Built from source
/opt/homebrew/Cellar/php/8.2.5 (520 files, 83.4MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-04-28 at 10:09:17
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/php.rb
License: PHP-3.01
==> Dependencies
Build: httpd, pkg-config
Required: apr, apr-util, argon2, aspell, autoconf, curl, freetds, gd, gettext, gmp, icu4c, krb5, libpq, libsodium, libzip, oniguruma, openldap, openssl@1.1, pcre2, sqlite, tidy-html5, unixodbc
==> Options
--HEAD
    Install HEAD version
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

    
        SetHandler application/x-httpd-php
    

Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
    /opt/homebrew/etc/php/8.2/

To restart php after an upgrade:
  brew services restart php
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
==> Analytics
install: 1,787 (30 days), 133,829 (90 days), 1,247,828 (365 days)
install-on-request: 1,619 (30 days), 118,431 (90 days), 1,089,426 (365 days)
build-error: 0 (30 days)
brew info openssl
==> openssl@3: stable 3.1.0 (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/opt/homebrew/Cellar/openssl@3/3.1.0 (6,494 files, 28.4MB)
  Poured from bottle using the formulae.brew.sh API on 2023-04-28 at 10:08:55
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@3.rb
License: Apache-2.0
==> Dependencies
Required: ca-certificates
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /opt/homebrew/etc/openssl@3/certs

and run
  /opt/homebrew/opt/openssl@3/bin/c_rehash

openssl@3 is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides LibreSSL.

If you need to have openssl@3 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@3 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"

For pkg-config to find openssl@3 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"
==> Analytics
install: 5,478 (30 days), 481,628 (90 days), 2,157,121 (365 days)
install-on-request: 2,451 (30 days), 108,406 (90 days), 1,115,433 (365 days)
build-error: 604 (30 days)
openssl version -a
LibreSSL 3.3.6
built on: date not available
platform: information not available
options:  bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) blowfish(idx) 
compiler: information not available
OPENSSLDIR: "/private/etc/ssl"
openssl ciphers
AEAD-CHACHA20-POLY1305-SHA256:AEAD-AES256-GCM-SHA384:AEAD-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:GOST2012256-GOST89-GOST89:DHE-RSA-CAMELLIA256-SHA256:DHE-RSA-CAMELLIA256-SHA:GOST2001-GOST89-GOST89:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:CAMELLIA256-SHA256:CAMELLIA256-SHA:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-CAMELLIA128-SHA256:DHE-RSA-CAMELLIA128-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:CAMELLIA128-SHA256:CAMELLIA128-SHA:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:RC4-SHA:RC4-MD5:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:DES-CBC3-SHA
sudo nginx -t
nginx: the configuration file /opt/homebrew/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/homebrew/etc/nginx/nginx.conf test is successful
which -a php-fpm
/opt/homebrew/sbin/php-fpm
/opt/homebrew/sbin/php-fpm
/opt/homebrew/opt/php/sbin/php-fpm -v
PHP 8.2.5 (fpm-fcgi) (built: Apr 13 2023 17:59:48)
Copyright (c) The PHP Group
Zend Engine v4.2.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.5, Copyright (c), by Zend Technologies
sudo /opt/homebrew/opt/php/sbin/php-fpm -y /opt/homebrew/etc/php/8.2/php-fpm.conf --test
[28-Apr-2023 10:44:16] NOTICE: configuration file /opt/homebrew/etc/php/8.2/php-fpm.conf test is successful
ls -al ~/Library/LaunchAgents | grep homebrew
-rw-r--r--    1 diego  staff   781 Apr  8 00:18 homebrew.mxcl.php.plist
ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--   1 root  admin   797 Apr 28 10:18 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 root  admin   685 Apr 28 10:43 homebrew.mxcl.nginx.plist
-rw-r--r--   1 root  admin   781 Apr 28 10:18 homebrew.mxcl.php.plist
ls -al /Library/LaunchDaemons | grep "com.laravel.valet."

ls -aln /etc/resolv.conf
lrwxr-xr-x  1 0  0  22 Apr  1 12:46 /etc/resolv.conf -> ../var/run/resolv.conf
cat /etc/resolv.conf
#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
#   scutil --dns
#
# SEE ALSO
#   dns-sd(1), scutil(8)
#
# This file is automatically generated.
#
search lan
nameserver 192.168.86.1
ifconfig lo0
lo0: flags=8049 mtu 16384
    options=1203
    inet 127.0.0.1 netmask 0xff000000 
    inet6 ::1 prefixlen 128 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    nd6 options=201
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"'
------
/opt/homebrew/etc/nginx/valet/valet.conf
---

3:    #listen VALET_LOOPBACK:80; # valet loopback

------
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'
------
~/.config/valet/dnsmasq.d/tld-off.conf
---

address=/.off/127.0.0.1
listen-address=127.0.0.1

------
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'
------
~/.config/valet/nginx/abe.off
---

3:    #listen 127.0.0.1:80; # valet loopback
10:    #listen 127.0.0.1:443 ssl http2; # valet loopback
54:    #listen 127.0.0.1:60; # valet loopback

------

------
~/.config/valet/nginx/bluehorseentries.off
---

3:    #listen 127.0.0.1:80; # valet loopback
10:    #listen 127.0.0.1:443 ssl http2; # valet loopback
54:    #listen 127.0.0.1:60; # valet loopback

------

------
~/.config/valet/nginx/l8.off
---

3:    #listen 127.0.0.1:80; # valet loopback
10:    #listen 127.0.0.1:443 ssl http2; # valet loopback
54:    #listen 127.0.0.1:60; # valet loopback

------

------
~/.config/valet/nginx/l8c.off
---

5:    #listen 127.0.0.1:80; # valet loopback
50:    #listen 127.0.0.1:60; # valet loopback

------

------
~/.config/valet/nginx/racepassport.off
---

3:    #listen 127.0.0.1:80; # valet loopback
10:    #listen 127.0.0.1:443 ssl http2; # valet loopback
54:    #listen 127.0.0.1:60; # valet loopback

------
diegovogel commented 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.

drbyte commented 1 year ago

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.

diegovogel commented 1 year ago

@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. image

drbyte commented 1 year ago

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

drbyte commented 1 year ago

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)

diegovogel commented 1 year ago

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

drbyte commented 1 year ago

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".

drbyte commented 1 year ago

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?

diegovogel commented 1 year ago

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 😆

diegovogel commented 1 year ago

@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?

drbyte commented 1 year ago

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:

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

drbyte commented 1 year ago

Or you could just explore whatever small adjustments might be made to Valet's WP driver to accommodate limitations that LocalWP meets.

diegovogel commented 1 year ago

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.

drbyte commented 1 year ago

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.

drbyte commented 1 year ago

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.

diegovogel commented 1 year ago

Thanks again!

drbyte commented 1 year ago

@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

diegovogel commented 1 year ago

@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.

drbyte commented 1 year ago

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.

diegovogel commented 1 year ago

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!

drbyte commented 1 year ago

but I set up a proxy through Valet and it works!

Yay!