admin管理员组

文章数量:814948

此请求已被阻止;从S3向EC2节点端点发出请求时,必须通过HTTPS错误提供内容

我的反应网站终端节点托管在AWS S3中,而触发电子邮件的节点终端节点部署在EC2实例中。我可以使用以下代码在本地命中EC2实例:

app.post('/api/email', (req, res, next) => {
sendGrid.setApiKey(config_data.SENDGRID_API_KEY);
const msg = {
    to: '[email protected]',
    from: '[email protected]',
    subject: req.body.email',
    text: req.body.message
}

命中EC2端点/ api / email的代码:

    Axios.post('http://public-IPv4:EC2_PORT_NUM/api/email', this.state)
        .then( res => {
            if(res.data.success){

              this.setState({
                disabled: false,
                emailSent: true
              });
            } else{
                this.setState({
                    disabled: false,
                    emailSent: false
                });
            }
        })
        .catch(err => {
            console.log(err.response.data);
            this.setState({
                disabled: false,
                emailSent: false
            });
        });

当代码在本地部署时,将根据需要触发电子邮件。但是,当我在S3中部署Web终结点并尝试触发电子邮件时,会出现以下错误:

Mixed Content: The page at 'https://mywebsiteaddress/api/email' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint '<ENDPOINT_LINK>'. This request has been blocked; the content must be served over HTTPS.

在本地,我可以使用'HTTP'(http://public-IPv4:EC2_PORT_NUM/api/email)发出请求,但通过S3可以请求'HTTPS'。然后,我将链接更改为“ HTTPS”,但仍然无法在本地或S3上运行。请让我知道如何解决此问题。预先感谢。

编辑:更新了EC2入站安全规则以接受HTTPS。

正在获得连接从本地和S3拒绝。请协助。

回答如下:

混合内容错误从您的Web浏览器返回:https://developers.google/web/fundamentals/security/prevent-mixed-content/what-is-mixed-content

这是出于安全原因。当您使用https协议打开前端网站(托管S3)时,用于任何XHR请求的Web浏览器也将需要https。

要解决它,您需要向您的EC2实例提供SSL证书,或尝试使用http://而不是https://加载S3页面。>

本文标签: 此请求已被阻止从S3向EC2节点端点发出请求时,必须通过HTTPS错误提供内容