问题描述
我的项目部署在 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);
});
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 (将#修改为@)