ryoluo / sail-ssl Goto Github PK
View Code? Open in Web Editor NEWLaravel Sail plugin to enable SSL (HTTPS) connection with Nginx.
License: MIT License
Laravel Sail plugin to enable SSL (HTTPS) connection with Nginx.
License: MIT License
Hello,
I've installed a project on a new computer and upon launching docker, I noticed that nginx imediately quits.
I see this message in the logs:
2023-06-09 10:45:55 nginx: [emerg] cannot load certificate "/etc/nginx/certs/server.pem": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/nginx/certs/server.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)
I tried rebuilding from docker-compose, deleted the image and the container, but still nothing. I also tried sail artisan sail-ssl:install
but reports everything is set correctly.
My docker-compose.yml seems ok too:
nginx:
image: 'nginx:latest'
ports:
- '${HTTP_PORT:-8000}:80'
- '${SSL_PORT:-443}:443'
environment:
- SSL_PORT=${SSL_PORT:-443}
- APP_SERVICE=${APP_SERVICE:-laravel.test}
- SERVER_NAME=${SERVER_NAME:-localhost}
volumes:
- 'sail-nginx:/etc/nginx/certs'
- './docker/nginx/templates:/etc/nginx/templates'
- './vendor/ryoluo/sail-ssl/nginx/generate-ssl-cert.sh:/docker-entrypoint.d/99-generate-ssl-cert.sh'
What should I do?
Thank you for your help.
Hi, I've been trying to implement this solution, it looks really nice! Although, I had no chance in getting it to work. Not sure but it could be because of the port I'm using?
nginx:
image: 'nginx:latest'
ports:
- '${HTTP_PORT:-8000}:80'
- '${SSL_PORT:-443}:443'
environment:
- SSL_PORT=${SSL_PORT:-443}
- APP_SERVICE=${APP_SERVICE:-laravel.test}
- SERVER_NAME=${SERVER_NAME:-localhost}
volumes:
- 'sail-nginx:/etc/nginx/certs'
- './vendor/ryoluo/sail-ssl/nginx/templates:/etc/nginx/templates'
- './vendor/ryoluo/sail-ssl/nginx/generate-ssl-cert.sh:/docker-entrypoint.d/99-generate-ssl-cert.sh'
depends_on:
- ${APP_SERVICE:-laravel.test}
networks:
- gng
gg_web:
build:
context: ./vendor/laravel/sail/runtimes/8.2
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.2/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-50080}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
IGNITION_LOCAL_SITES_PATH: '${PWD}'
volumes:
- '.:/var/www/html'
networks:
- gng
depends_on:
- gg_mysql
And in .env
:
APP_SERVICE=gg_web
I'm having logs about WARN 172.24.0.1:46352 Invalid request (Unsupported SSL request).
Did I miss something?
Hello,
Laravel 10, using Sail, through docker-compose. After successfully doing composer require ryoluo/sail-ssl --dev,
I get this error, There are no commands defined in the "sail-ssl" namespace.
How does one revert this back to localhost? this change wasnt mentioned in the readme and breaks my local.
Error response from daemon: driver failed programming external connectivity on endpoint test-nginx-1 (): Bind for 0.0.0.0:443 failed: port is already allocated
After install this I can access the site with https://localhost, but trying to enter username password it always fail, while using http://localhost is working fine. What would it causes the issue? How should I fix this.
server {
listen 443 ssl default_server;
server_name ${SERVER_NAME};
# Self signed certificates
# Don't use them in a production server!
ssl_certificate /etc/nginx/certs/server.pem;
ssl_certificate_key /etc/nginx/certs/server.key;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://${APP_SERVICE}:8000;
}
}
When I've tryed install in my Laravel 10 app, my shell console returns:
$ sail composer require ryoluo/sail-ssl --dev
Info from https://repo.packagist.org: #StandWithUkraine
./composer.json has been updated
Running composer update ryoluo/sail-ssl
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires ryoluo/sail-ssl * -> satisfiable by ryoluo/sail-ssl[v1.0.0, ..., v1.1.1].
- ryoluo/sail-ssl[v1.0.0, ..., v1.1.1] require illuminate/console ^8.0|^9.0 -> found illuminate/console[v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.0] but these were not loaded, likely because it conflicts with another require.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require ryoluo/sail-ssl:*" to figure out if any version is installable, or "composer require ryoluo/sail-ssl:^2.1" if you know which you need.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
I got certificates by certbot certonly (fullchaine.pem & privkey.pem), indicate path in yml 'sail-nginx:/etc/letsencrypt/live/site.domain/' but still failure: (I even copied fullchaine.pem as server.pem to mentioned path without result, also I updated rights by sudo chmod -R 775 , but without result)
mfa-nginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
mfa-nginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/99-generate-ssl-cert.sh
mfa-nginx-1 | 99-generate-ssl-cert.sh: Server certificate already exists, do nothing.
mfa-nginx-1 | /docker-entrypoint.sh: Configuration complete; ready for start up
mfa-nginx-1 | 2023/09/11 19:26:26 [emerg] 1#1: cannot load certificate "/etc/nginx/certs/server.pem": BIO_new_file() failed (SSL: error:80000002:system library::No such file or directory:calling fopen(/etc/nginx/certs/server.pem, r) error:10000080:BIO routines::no such file)
mfa-nginx-1 | nginx: [emerg] cannot load certificate "/etc/nginx/certs/server.pem": BIO_new_file() failed (SSL: error:80000002:system library::No such file or directory:calling fopen(/etc/nginx/certs/server.pem, r) error:10000080:BIO routines::no such file)
In Laravel 10.10, when I try to run the package commands, I get
ERROR There are no commands defined in the "sail-ssl" namespace.
At a glance, it looks like you're registering them correctly with the commands() method of your service provider, so I'm not sure what the issue is. I can confirm the service provider is loading and the registerCommands method is being called.
If I add this to my console kernel, they work.
protected $commands = [
\Ryoluo\SailSsl\Console\InstallCommand::class,
\Ryoluo\SailSsl\Console\PublishCommand::class
];
Although the https conversion was successful, the certificate is invalid.
Hi,
Thanks for your great package and to share it :-)
To make it compatible with custom port and host we have to provide headers used by laravel/symfony X_FORWARDED_HOST
, X_FORWARDED_PROTO
and X_FORWARDED_PORT
in the nginx configuration.
map $http_host $port {
default 80;
"~^[^\:]+:(?<p>\d+)$" $p;
}
server {
...
location / {
...
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $port;
...
If you're looking for a way to make this work with vite, use this:
vite.config.js
import { defineConfig } from "vite";
import laravel from "laravel-vite-plugin";
export default defineConfig({
plugins: [
laravel({
input: ["resources/css/app.css", "resources/js/app.js"],
refresh: true,
}),
],
server: {
hmr: {
host: "localhost",
},
},
});
Don't forget to include this in your AppServiceProvider.php
public function boot(): void
{
\Illuminate\Support\Facades\URL::forceScheme('https');
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.