Search code examples
regexnginxnginx-locationlaravel-valet

Laravel Valet nginx location regex not working on Mac Catalina


I'm working with Laravel Valet but when adding some regular expression location that works perfectly on forge Linux server, doesn't work for MacOS. It doesn't give any errors just doesn't load any of the right css. The regex is for css/js versioning. See code below:

location ~* (.+)\.(?:\d+)\.(css|js|gif|png|jpg|jpeg)$ {
    try_files $uri $1.$2;
}

added just before

location / {
    rewrite ^ "/Users/home/.composer/vendor/laravel/valet/server.php" last;
}

in valet.conf file


Solution

  • Solved by using a custom Valet Driver, it's just php and you can use it to play with the incoming request and return the desired url or response. In this case I created a LocalValetDriver in the project root folder and skip the numeric portion of the filename in the isStaticFile function, just remember to return true on the server function so your custom driver will be used.

    For more info on custom drivers, feel free to visit Valet's documentation here.