-
-
Save MMTE/0e86f0e99895bfd566ba9565b2d0a8ae to your computer and use it in GitHub Desktop.
Enabling HTTPS (SSL) for Laravel Sail using Caddy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# app/Http/Controllers/CaddyController.php | |
namespace App\Http\Controllers; | |
use App\Store; | |
use Illuminate\Http\Request; | |
class CaddyController extends Controller | |
{ | |
public function check(Request $request) | |
{ | |
$authorizedDomains = [ | |
'laravel.test', | |
'www.laravel.test', | |
// Add subdomains here | |
]; | |
if (in_array($request->query('domain'), $authorizedDomains)) { | |
return response('Domain Authorized'); | |
} | |
// Abort if there's no 200 response returned above | |
abort(503); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# docker/Caddyfile | |
{ | |
on_demand_tls { | |
ask http://laravel.test/caddy-check | |
} | |
local_certs | |
} | |
:443 { | |
tls internal { | |
on_demand | |
} | |
reverse_proxy laravel.test { | |
header_up Host {host} | |
header_up X-Real-IP {remote} | |
header_up X-Forwarded-For {remote} | |
header_up X-Forwarded-Port {server_port} | |
header_up X-Forwarded-Proto {scheme} | |
health_timeout 5s | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
caddy: | |
image: caddy:latest | |
restart: unless-stopped | |
ports: | |
- '80:80' | |
- '443:443' | |
volumes: | |
- './docker/Caddyfile:/etc/caddy/Caddyfile' | |
- sailcaddy:/data | |
- sailcaddy:/config | |
networks: | |
- sail | |
# Remove "ports" from laravel.test service | |
volumes: | |
sailcaddy: | |
driver: local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# routes/web.php | |
Route::get('/caddy-check', 'CaddyController@check'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment