Laravel's Valet project for MacOS uses NGINX. NGINX has recently started throwing 500 errors for all static assets, but runs PHP fine for my Laravel site. I'd really like to get Valet back to serving the whole of my site, and I'm pretty sure this is an NGINX misconfiguration or a system sockets issue, but I don't know how to further diagnose. Here's what I know so far.
PHP is parsed and delivered fine via the fastcgi route, but any static file that NGINX attempts to serve throws a 500 error (lightly formatted for legibility:
2022/04/20 10:43:50 [crit] 537#0: *83 open() "/Users/user/example/public/favicon.ico" failed (1: Operation not permitted),
client 127.0.0.1,
server: ,
request: "GET /favicon.ico HTTP/1.1",
upstream: "fastcgi://unix:/Users/user/.config/valet/valet.sock",
host: "example.test",
referrer: "http://example.test/favicon.ico"
Valet serves static assets using the X-Accel-Redirect
header and has the following default NGINX config file for all http sites:
server {
listen 127.0.0.1:80 default_server;
#listen VALET_LOOPBACK:80; # valet loopback
root /;
charset utf-8;
client_max_body_size 128M;
location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
internal;
alias /;
try_files $uri $uri/;
}
location / {
rewrite ^ "/Users/user/.composer/vendor/laravel/valet/server.php" last;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log "/Users/user/.config/valet/Log/nginx-error.log" warn;
error_page 404 "/Users/user/.composer/vendor/laravel/valet/server.php";
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass "unix:/Users/user/.config/valet/valet.sock";
fastcgi_index "/Users/user/.composer/vendor/laravel/valet/server.php";
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME "/Users/user/.composer/vendor/laravel/valet/server.php";
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
}
The first location block is arrived at via Valet's serveStaticFiles()
function in the ValetDriver
abstract class.
public function serveStaticFile($staticFilePath, $sitePath, $siteName, $uri)
{
header('Content-Type: text/html');
header_remove('Content-Type');
header('X-Accel-Redirect: /'.VALET_STATIC_PREFIX.$staticFilePath);
}
When a static file doesn't exist, Valet returns the Laravel 404 page. Which means that the 500 error only occurs when file actually exists. I confirmed all static files have permissions -rw-r--r--
and the parent directory is set to drwxr-xr-x
.
I confirmed NGINX is erroring in that block by editing it to the following:
location /41c270e4-5535-4daa-b23e-c269744c2f45/ {
return 200 works;
# internal;
# alias /;
# try_files $uri $uri/;
}
at which navigating to a static asset will return the text string 'works'. As a sanity check (and in response to the Operation not permitted
error message), I've also tried setting the file permissions to 777 for the file and parent directory, and that does not resolve the issue.
I'm at a loss to further fix the problem. I've tried uninstalling and reinstalling Valet, and all its dependencies (NGINX, PHP, Dnsmasq). Additionally, Valet was running fine until I recently tried to configure Valet for different versions of PHP on a per-site basis. This makes me think that the fastcgi socket is somehow involved/corrupted, but that is me grasping at straws and outside my wheelhouse to debug.
What do I try next?