How to Serve Laravel Application in handle or handle_path directives

1. The problem I’m having:

I have multiple apps and I only have 1 DNS. To separate the apps, I add prefix in the URI, e.g. www.domain.test/app-1, www.domain.test/app-2, and so on. So I preferred to use handle or handle_path directives in my configurations. The Problem: Only my laravel application always ends-up to 404 Not Found.

2. Error messages and/or full log output:

![image|690x325](upload://9cYbm5HQ7ehqr8LD9KW2CREbs96.png)

3. Caddy version:

v2.7.4

4. How I installed and ran Caddy:

a. System environment:

OS: Ubuntu 22.04.3 LTS 22.04 Jammy
Laravel: v9

b. My complete Caddy config:

sub.domain.test {
   encode zstd gzip
   import static
   import security

   handle_path /alias-laravel-app* {
     root * /var/www/html/laravel-app/public
     php_fastcgi unix//var/run/php/php8.1-fpm.sock
   }
   
   root * /var/www/html/
   php_fastcgi unix//var/run/php/php7.4-fpm.sock
   file_server
}

5. Links to relevant resources:

You’ll need to configure your routes (in web.php probably) to be aware of /alias-laravel-app as a base. You can wrap all your routes like this:

Route::prefix('alias-laravel-app')->group(function () {
    // Your routes here
});

See this article:

Ultimately the key is that your upstream app needs to be aware of being run within a subpath.

It worked, Thanks for the idea.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.