混合内容:“domain”处的页面是通过 HTTPS 加载的,但请求了不安全的 XMLHttpRequest 端点

Art*_*nov 6 ssl inertiajs laravel vue.js vuejs3

我一直在尝试解决仅在生产中发生的错误。当我尝试create新的数据库条目时,会引发以下错误:

Mixed Content: The page at 'https://strong-moebel.art/admin/gallerie/neu' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://strong-moebel.art/admin/gallerie'. This request has been blocked; the content must be served over HTTPS.
Run Code Online (Sandbox Code Playgroud)
Uncaught (in promise) Error: Network Error
    at wh (main.750d1ea1.js:4:96980)
    at s.onerror (main.750d1ea1.js:5:1837)
Run Code Online (Sandbox Code Playgroud)

其他一切都有效,包括edit条目的方法。我正在使用一个resource controller. create方法使用惯性form.postedit方法使用其form.put(如果相关的话)。

我一直在尝试使用以下提供的解决方案来调试此问题:

  1. 混合内容问题 - 内容必须以 HTTPS 形式提供
  2. 混合内容(laravel)

基本上人们都说要添加:

if (App::environment('production')) {
    URL::forceScheme('https');
}
Run Code Online (Sandbox Code Playgroud)

按照boot()你的方法AppServiceProvider.php。我已经这样做了,但错误仍然出现。我想知道这是否是一个惯性问题。

在服务器上,我尝试过:

APP_ENV=production
APP_URL=http://localhost
APP_URL=https://localhost
APP_URL=
APP_URL=http://strong-moebel.art
APP_URL=https://strong-moebel.art
Run Code Online (Sandbox Code Playgroud)

但似乎没有什么能解决这个问题。我的虚拟主机是 cloudways,我正在使用他们的Let's Encrypt SSL Certificate. 我还尝试删除证书并查看会发生什么,但即使如此,也会发生完全相同的错误。我受过的教育不多SSL,想知道是否有人可以帮助我解决问题或指出我可以调查的内容。

我正在使用vite构建生产构建。

更新

通过以下方式发送请求的组件form.post

<template layout="backend/cms-layout">
  <div id="cms-gallery-create" class="cms-gallery-create">
    <form @submit.prevent="storeRecord" method="post" enctype="multipart/form-data">
      <div class="title-btn-bar">
        <h1>Erstelle eine Kreation:</h1>
        <input type="submit" class="btn" value="Kreation speichern">
      </div>
      <p>Titel:</p>
      <input class="textfield-closed title-field" v-model="form.title">
      <p>Titelbild:</p>
      <cms-img-upload v-model:image="form.image"/>
      <p>Hauptteil:</p>
      <cms-custom-editor v-model="form.body"/>
    </form>
    <div v-if="errors.target" class="error">{{ errors.target }}</div>
  </div>
</template>


<script setup>
import CmsImgUpload from '../../components/backend/cms-img-upload.vue'
import CmsCustomEditor from '../../components/backend/cms-custom-editor.vue'
import {useForm} from "@inertiajs/inertia-vue3";

const props = defineProps({
    errors: Object
})

const form = useForm({
    title: '',
    body: '',
    image: '',
})

const storeRecord = () => {
    form.post('/admin/gallerie/')
}

</script>
Run Code Online (Sandbox Code Playgroud)

然后它被路由inertia到后端 -> web.php

Route::middleware('auth')->group(function() {
    Route::inertia('/admin/dashboard', 'backend/cms-dashboard');

    Route::post('/admin/gallerie/move', [GalleryController::class, 'moveRow']);
    Route::resource('/admin/gallerie', GalleryController::class);

    Route::post('/admin/verkauf/move', [ShopController::class, 'moveRow']);
    Route::resource('/admin/verkauf', ShopController::class);

    Route::post('/admin/logout', [LoginController::class, 'destroy']);
});
Run Code Online (Sandbox Code Playgroud)

并发送到resource controller通过:

Route::resource('/admin/gallerie', GalleryController::class);
Run Code Online (Sandbox Code Playgroud)

在控制器内部,调用此方法将请求数据存储在数据库中:

public function store(Request $request)
{
    if ($request->image) {
        $image_path = Custom::storeBase64Image($this->STORAGE_PATH, $request);
    } else {
        $image_path = null;
    }

    Gallery::create([
        'title' => $request->title,
        'body' => $request->body,
        'image_path' => $image_path
    ]);

    return redirect($this->BASE_URL);
}
Run Code Online (Sandbox Code Playgroud)

问题似乎发生在前端,因为没有logs创建。

Sim*_*tia 6

我遇到了这个错误,并尝试了上面几乎所有的建议,但没有任何效果。然而,我遇到了一篇中等帖子,建议添加以下元标记,它对我有用。

<head>
 <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
</head>
Run Code Online (Sandbox Code Playgroud)

因此,如果您使用 Laravel,您基本上需要在主布局文件的 head 标记中添加该元标记。欲了解更多信息,请阅读 这篇文章


Art*_*nov 4

感谢@PaulTsai,它现在可以工作了。我必须改变:

form.post('/admin/gallerie/')
Run Code Online (Sandbox Code Playgroud)

到:

form.post('/admin/gallerie')
Run Code Online (Sandbox Code Playgroud)

Edit

我刚刚遇到了完全相同的问题,但是是fetchapi,这次是paypal. 在生产中我必须改变:

fetch('/api/paypal/order/create/', ...
Run Code Online (Sandbox Code Playgroud)

到:

fetch('/api/paypal/order/create', ...
Run Code Online (Sandbox Code Playgroud)

也许它可以帮助某人