gpt4 book ai didi

Laravel + Vite + 通过 HTTPS 航行。可能的?

转载 作者:行者123 更新时间:2023-12-01 22:56:41 26 4
gpt4 key购买 nike

经过几个小时的尝试,我想我太困惑了,无法理解出了什么问题……标题完美地解释了我正在努力使工作成为可能。我的 docker-compose.yml:

version: '3'
services:
mysite.test:
build:
context: ./docker/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '443:443' //added for test but not working...
- '${HMR_PORT:-8080}:8080'
- '5173:5173' //Vite port
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- minio
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sail-nginx:
driver: local
sail-mysql:
driver: local

我的vite.config.js:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';

export default defineConfig({
server: {
https: true,
host: '0.0.0.0'
},
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
],
refresh: true
}),
],
});

我的.env:

(...)
APP_URL=https://mysite.test
APP_SERVICE=mysite.test
(...)

该配置的结果是它与 http://mysite.test 一起工作但不在 https 中。返回:

无法访问此站点

mysite.test 意外关闭了连接。

有人给我提示吗? 🙏谢谢!

最佳答案

我设法使用以下要点与 Caddy 一起工作 https://gist.github.com/gilbitron/36d48eb751875bebdf43da0a91c9faec

完成上述所有操作后,我将 vite 端口添加到 laravel.test 服务下的 docker-compose.yml

ports:
- '5173:5173'

另外vite本身也需要ssl证书

vite.config.js:

import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import vue from '@vitejs/plugin-vue';
import basicSsl from '@vitejs/plugin-basic-ssl'

export default defineConfig({
server: {
https: true,
host: '0.0.0.0',
hmr: {
host: 'localhost'
},
},
plugins: [
basicSsl(),
laravel({
input: 'resources/js/app.js',
refresh: true,
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
],
});

出于某种原因,我的应用生成了 http 链接,而不是 https。所以我将以下内容添加到我的 AppServiceProvider.php

boot 方法中
\URL::forceScheme('https');

关于Laravel + Vite + 通过 HTTPS 航行。可能的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73036658/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com