ryoluo / sail-ssl
Laravel Sail plugin to enable SSL (HTTPS) connection with Nginx.
Installs: 633 651
Dependents: 1
Suggesters: 0
Security: 0
Stars: 187
Watchers: 2
Forks: 24
Open Issues: 3
pkg:composer/ryoluo/sail-ssl
Requires
- php: ^7.3|^8.0
- illuminate/console: >=8.0
- illuminate/contracts: >=8.0
- illuminate/support: >=8.0
- symfony/yaml: ^5.4|^6.0|^7.0
Requires (Dev)
- laravel/sail: ^1.14
- orchestra/testbench: >=6.0
- phpunit/phpunit: >=9.5
This package is auto-updated.
Last update: 2026-02-22 05:58:44 UTC
README
Laravel Sail plugin to enable SSL (HTTPS) connection with Nginx.
Install
You need to setup Laravel Sail environment before using the plugin.
With local PHP / Composer:
composer require ryoluo/sail-ssl --dev php artisan sail-ssl:install ./vendor/bin/sail up
With Sail container:
./vendor/bin/sail up -d ./vendor/bin/sail composer require ryoluo/sail-ssl --dev ./vendor/bin/sail artisan sail-ssl:install ./vendor/bin/sail down ./vendor/bin/sail up
After containers started, you can access https://localhost.
Update AppServiceProvider
Since the application is behind an Nginx reverse proxy that handles SSL, Laravel needs to be configured to generate HTTPS URLs. Add URL::forceScheme('https') to your AppServiceProvider:
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Register any application services. */ public function register(): void { // } /** * Bootstrap any application services. */ public function boot(): void { \Illuminate\Support\Facades\URL::forceScheme('https'); } }
Without this setting, Laravel may generate HTTP URLs for assets, routes, etc., even though the site is served over HTTPS.
Trust the certificate (optional)
The plugin generates a local Root CA certificate to sign the server certificate. You can import the Root CA into your browser to remove the security warning.
1. Copy the Root CA certificate to your host machine:
./vendor/bin/sail cp nginx:/etc/nginx/certs/root-ca.crt .
2. Import the certificate:
- Chrome: Settings > Privacy and Security > Security > Manage certificates > Authorities > Import
- Firefox: Settings > Privacy & Security > Security > View Certificates > Authorities > Import
- macOS: Double-click the
root-ca.crtfile to open Keychain Access, then set "Always Trust"
Note: If you change
SSL_DOMAINorSSL_ALT_NAME, remove the Docker volumesail-nginxto regenerate certificates:docker volume rm sail-nginx
Environment variables
SERVER_NAME- Determine
server_namedirective in nginx.conf - Default:
localhost
- Determine
APP_SERVICE- Specify Laravel container name in docker-compose.yml
- Default:
laravel.test
HTTP_PORT- Port to forward Nginx HTTP port
- By default, request for this port would redirect to
SSL_PORT - Default:
8000
SSL_PORT- Port to forward Nginx HTTPS port
- Default:
443
SSL_DOMAIN- The Common Name to use in the SSL certificate, e.g.
SSL_DOMAIN=*.mydomain.test - Required to generate a valid certificate for a domain other than
localhost - Default:
localhost
- The Common Name to use in the SSL certificate, e.g.
SSL_ALT_NAME- The Subject Alternative Name to use in the SSL certificate, e.g.
SSL_ALT_NAME=DNS:localhost,DNS:mydomain.test - Required to generate a valid certificate for a domain other than
localhost - Default:
DNS:localhost
- The Subject Alternative Name to use in the SSL certificate, e.g.
Configure Nginx
./nginx/templates/default.conf.template will be published.
php artisan sail-ssl:publish
Contribution
Feel free to create a PR!