My experience with this problem has been with laravel inside a docker environment.
With this configuration my environment is now working with SSL certs and dockerized vite configuration.
My docker-compose.yml
services:
app:
ports:
- "80:80"
- "443:443"
- "9003:9003"
- "5173:5173"
extra_hosts:
- "myhostname.com:0.0.0.0"
My vite.config.js:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import fs from 'fs';
const key = fs.readFileSync('/etc/ssl/private/myhostname.com.key');
const cert = fs.readFileSync('/etc/ssl/certs/myhostname.com.pem');
export default defineConfig({
//...Omitted...//
server: {
host: 'myhostname.com',
port: 5173,
https: {
key: key,
cert: cert,
},
hmr: {
host: 'myhostname.com',
port: 5173,
},
},
});
If you want to use SSL certification with a custom local hostname, you finally have to insert a record in the /etc/hosts file on your host machine like this:
127.0.0.1 myhostname.com
Hope that can helps someone.