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

it@myswooop.de's avatar

Laravel 6.10 behind NGINX proxy in Docker swarm

[SOLVED BUT NOT AS EXPECTED :)]

Hi community,

i am currently setting up a laravel application in a docker swarm. since there are other webprojects in the swarm i use a nginx proxy in front of it. the proxy itselfs talks plain http to the application.

I am using TrustedProxies Middleware as described here:

https://laravel.com/docs/6.x/requests#configuring-trusted-proxies

However assets are still served via http and i am unable to login.

I found two problems here:

Asterisks for proxies does not seem to work. However since it accepts CIDR and docker swarm internal networks are all in the 10.0.0.0/8 range i changed the middleware to that.

Also i am passing the the server name as X-Forwarded-Host since otherwise it will report the IP of the swarm LB.

The configs below work for me:

nginx config:

server {
   listen       80;
   server_name laravel.vm;

    location / {
      return 301 https://$host$request_uri;
    }
}

server {
    listen       443 ssl;
    server_name laravel.vm;
    ssl_certificate /sscert/cert.pem;
    ssl_certificate_key /sscert/key.pem;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_pass http://laravel;
    }
}

middleware:

<?php

namespace App\Http\Middleware;

use App\Http\Requests\Request;
use Fideloper\Proxy\TrustProxies as Middleware;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array
     */
    protected $proxies = [
        '10.0.0.0/8',
    ];

    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers = Request::HEADER_X_FORWARDED_PROTO;

   
}

0 likes
0 replies

Please or to participate in this conversation.