Logo

dev-resources.site

for different kinds of informations.

How to Set Up Laravel in a Subfolder Using Traefik

Published at
1/3/2025
Categories
docker
laravel
traefik
php
Author
ferri
Categories
4 categories in total
docker
open
laravel
open
traefik
open
php
open
Author
5 person written this
ferri
open
How to Set Up Laravel in a Subfolder Using Traefik

Here’s how you can run Laravel in a subfolder with Traefik. Let’s consider this scenario:

  • Traefik is already installed with entry points http and https.
  • Laravel will be installed in the /app subfolder.
  • Traefik and Laravel will use an external network called traefik.

Edit docker-compose.yml as following:

services:
  app:
    image: your-app-image

    # ...the rest of the configuration

    networks:
      - traefik
    labels:
      - traefik.enable=true
      - traefik.docker.network=traefik
      - traefik.constraint-label=traefik

      - traefik.http.middlewares.app-strip.stripprefix.prefixes=/app

      # HTTP entrypoint
      - traefik.http.routers.app-http.entrypoints=http
      - traefik.http.routers.app-http.rule=Host(`your-app-domain.com`) && PathPrefix(`/app`)
      - traefik.http.routers.app-http.middlewares=https-redirect,app-strip

      # HTTPS  entrypoint
      - traefik.http.routers.app-https.entrypoints=https
      - traefik.http.routers.app-https.rule=Host(`your-app-domain.com`) && PathPrefix(`/app`)
      - traefik.http.routers.app-https.tls=true
      - traefik.http.routers.app-https.middlewares=app-strip

networks:
  traefik:
    external: true
Enter fullscreen mode Exit fullscreen mode

Edit .env and set the subfolder in APP_URL.

APP_URL=https://your-app-domain.com/app

# ...the rest of the configuration
Enter fullscreen mode Exit fullscreen mode

Edit app/Http/Middleware/TrustProxies.php and ensure that all proxies are allowed to let Laravel generate HTTPS URLs.

Always use URL helpers like url(), route(), etc., to generate full URLs, including the subfolder path.

That’s it! Now you can run your compose file with docker compose up -d and access your Laravel application via the subfolder.

traefik Article's
30 articles in total
Favicon
How to Set Up Laravel in a Subfolder Using Traefik
Favicon
Traefik using owned SSL certificate
Favicon
Traefik Cloudflare DNS Challenge
Favicon
Docker for Load Balancing: Scaling Applications Efficiently
Favicon
Comprehensive Guide to Setting Up Load Balancing with Traefik, Docker, Django, and React
Favicon
ForwardAuth with Traefik: Streamlining Security for Microservices
Favicon
Opening Pandora's Container - Gaining Host Access (Part 2)
Favicon
ForwardAuth with Traefik: Streamlining Security for Microservices
Favicon
Effortless Next.js Deployment with Docker, Traefik, and GitHub Actions: A Complete Hosted Solution
Favicon
Traefik Proxy Guide: Configuring public Domain Names for Docker Containers
Favicon
Setting Up a Multi-Purpose Server with Amazon EC2, Docker, and Traefik
Favicon
Traefik with docker compose
Favicon
Setting Up Traefik and mkcert for Local Development
Favicon
How to increase AWS ELB keep-alive timeout when deployed from Traefik
Favicon
Boost Your DevOps Workflow with Traefik
Favicon
Auto-route multiple web projects using Traefik
Favicon
My Github Actions workflow for deploying web projects
Favicon
Adding a new Ghost via docker-compose to your traefik setup
Favicon
Exposing public applications on AWS EKS with Traefik
Favicon
K3s Traefik Ingress - configured for your homelab!
Favicon
Traefik Proxy e Amazon ECS
Favicon
Random 1: Traefik blocks CORS by Default
Favicon
Instalando Zabbix Server com MySQL, Grafana e Traefik em Docker
Favicon
NGINX vs. Traefik vs. Istio — Unlocking the Secrets to Mastering Kubernetes Ingress
Favicon
Easy steps to install K3s with SSL certificate by traefik, cert manager and Let’s Encrypt
Favicon
Customizing error pages in Traefik v.2
Favicon
Redirect HTTP to HTTPS and WWW to Non-WWW with Traefik 3
Favicon
Deploying a Medusa + Minio + MeiliSearch stack with Docker and Traefik
Favicon
Централизованное логирование
Favicon
ECS Anywhere & Traefik Proxy with ECS Compose-X

Featured ones: