Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dust's avatar
Level 9

Laravel url() function in Docker container

I'm running Laravel with Octane with frankenPHP. It works fine but does not show images. I found that url() function in my views returns http://localhost:8002 which is docker address. I expect url() to return my domain name for example: http://example.com

In my docker-compose.yaml I have:

version: "3.9"
    services:
      app:
        image: "my_image:latest"
        entrypoint: php artisan octane:frankenphp
        restart: unless-stopped
        hostname: example.com
        ports:
          - "8002:8000"

My .env file:

APP_NAME=Laravel
APP_ENV=prod
APP_KEY=base64:api_key
APP_DEBUG=false
APP_URL=http://example.com

Does anyone know how to fix that?

0 likes
2 replies
hupp's avatar
hupp
Best Answer
Level 11

@dust

  1. Set the Trusted Proxies: In Laravel, when using a proxy, you need to specify which proxies should be trusted. Update your config/app.php file to include the following configuration for trusted proxies:
    'trusted_proxies' => [
        '127.0.0.1', // This is the default Docker IP for the host machine
    ],
    
    If you're using a reverse proxy or load balancer, you may need to add its IP address as well.
  2. Check X-Forwarded-For Header: Ensure that your reverse proxy (if you're using one) is forwarding the X-Forwarded-For header. Octane relies on this header to determine the client's IP address.
  3. Use HTTPS in APP_URL: If your production environment uses HTTPS, make sure to update your APP_URL to use HTTPS:
    APP_URL=https://example.com
    
  4. Check Octane Configuration: Make sure your Octane configuration is set up properly. Check the octane.php configuration file and ensure that the base_url is configured correctly.

After this build and restart docker container to make sure things work perfect. Also do clear the cache. Let me know your feedback

1 like
dust's avatar
Level 9

Thanks @hupp! The problem was that I hadn't set X-Forwarded-For in my NGINX. Thank you very much!

Please or to participate in this conversation.