我有一个反应应用程序连接到后端node.js.它适用于 http 但是当我强制执行 httpS 时,我在控制台中收到此错误:

混合内容:''的页面是通过HTTPS加载的,但请求了一个不安全的XMLHttpRequest endpoints '' . 此请求已被阻止;内容必须通过HTTPS提供 .

这是我的反应配置

const config = {
  api:{
    host: 'http://localhost:3000',
    sentinel: null // keep always last
  },
  auth: {
    cookieDomain: 'domain.com',
    tokenPrefix: 'domain',
    userStorageKey: 'aaabbb',
    sentinel: null // keep always last
  },
  captcha: {
    siteKey: '',
    sentinel: null // keep always last
  },
  search: {
    searchEngine: null,
    sentinel: null // keep always last
  },
  siteDomains: [ // for transform links in the posts, comments, etc.
    'domain.com'
  ],
  sentry: {
    publicDSN: null,
    sentinel: null // keep always last
  },
  frontendPreferences: {
    clientId: 'net.domain',
    defaultValues: {
      displayNames: {
        displayOption: FrontendPrefsOptions.DISPLAYNAMES_DISPLAYNAME,
        useYou: true
      },
      realtimeActive: false,
      comments: {
        omitRepeatedBubbles: true,
        highlightComments: true,
        hiddenTypes: []
      },
      allowLinksPreview: false,
      readMoreStyle: 'modern',
      homefeed: {
        hideUsers: []
      }
    }
  }
};

我的nginx配置来处理api:

server {
       listen      api.domain.com:80;
    server_name  api.domain.com;
    return 301   https://$server_name$request_uri;
}

server {

ssl on;

  listen api.domain.com:443;
  server_name api.domain.com;


ssl_certificate /etc/ssl/certs/mycerts/ssl-bundle.crt;
ssl_certificate_key /etc/ssl/certs/mycerts/private/myserver.key;

ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;

  location / {
   proxy_pass http://localhost:3000;
   proxy_http_version 1.1;
   proxy_set_header X-Forwarded-Proto https;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection 'upgrade';
   proxy_set_header Host $host;
   proxy_cache_bypass $http_upgrade;

  }
}

感谢您提示解决此问题 .