微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

混合内容错误:此请求已被阻止;内容必须在 AWS 上的 MERN 项目中通过 HTTPS 提供

如何解决混合内容错误:此请求已被阻止;内容必须在 AWS 上的 MERN 项目中通过 HTTPS 提供

我的项目部署在 AWS ec2 实例上。将 SSL 添加到我的域后,我开始收到此错误

混合内容:“https://example.com/”页面已加载 HTTPS,但请求了不安全的资源 'http://14.1.41.10/api/product/productsforcarousel'。这个请求有 被封锁;内容必须通过 HTTPS 提供。

这是一个 MERN 项目,放置 SSL 后问题就来了。这是我的代码

const fs = require("fs");
const path = require("path");
const express = require("express");
const mongoose = require("mongoose");

const app = express();

mongoose
  .connect(`mongodb+srv://${process.env.DB_URL}`,{
    useNewUrlParser: true,useUnifiedTopology: true,useFindAndModify: false,})
  .then(() => {
    app.listen(5000);   
  })
  .catch((err) => {
    console.log(err);
  });

这是Nginx代码

server {
    listen 80 default_server;
    server_name example.com www.example.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;

    root /var/www/Example_Pro/public;
    index index.PHP index.js index.html;

    server_name example.com www.example.com;

    ssl_certificate "/etc/Nginx/ssl/ssl.crt";
    ssl_certificate_key "/etc/Nginx/ssl/private.key";

    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_protocols TLSv1.2 TLSv1.3;

    ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256";

    location / {
    proxy_pass http://127.0.0.1:8043;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;

    proxy_read_timeout  90;
    proxy_buffering     off;
    proxy_redirect      http://127.0.0.1:8043  https://example.com;
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。