I'm trying to set up a server for an application that handles differently depending on the domain the request originated from. So a request from abc.company.com gets different content than xyz.company.com
I'm using docker to containerize the application and apache as an reverse proxy
My apache config looks like this:
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Redirect permanent / protocol_secure://company.com
</VirtualHost>
<VirtualHost *:443>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/company.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/company.com/privkey.pem
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLHonorCipherOrder On
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
# Requires Apache >= 2.4.11
SSLSessionTickets Off
# Proxy disable /http_errors to prevent errors with error messages from apache
ProxyPass /http_errors/ !
ProxyPass / protocol://localhost:1234/
ProxyPassReverse / protocol:// localhost:1234/
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
RequestHeader set "X-Forwarded-SSL" expr=%{HTTPS}
RequestHeader set X-Forwarded-Port "443"
</VirtualHost>
and my bootstrap/app.php like this
<?php
use App\Models\Customer;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php',
channels: __DIR__.'/../routes/channels.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->validateCsrfTokens(except: [
'/call-entry'
]);
$middleware->appendToGroup('api', [
\Illuminate\Cookie\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
]);
$middleware->trustProxies(at: [
'127.0.0.1'
], headers:
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO
);
$domains = [];
if (app()->runningInConsole() && (count($_SERVER['argv']) >= 2 && !in_array($_SERVER['argv'][1], ["key:generate", "migrate"]))) {
// Get hosts
$domains = Customer::all()->pluck('dashboard_domain')->toArray();
}
$domains[] = "company.com";
$middleware->trustHosts(at:$domains, subdomains:false);
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();
However if I print the domain with dd(url()->current()); its always returning protocol://localhost:1234
Btw. laracasts prevents me from including links (including localhost so I replaced http with protocol and protocol secure