【问题标题】:cors issue with nginx, aws and cloudflarenginx、aws 和 cloudflare 的 cors 问题
【发布时间】:2019-02-03 22:19:18
【问题描述】:

我的网站托管在亚马逊 AWS 中。我的应用程序前端是用 angular 构建的,后端是用 nodejs express 框架构建的。该域使用 Cloudflare 和来自 Cloudflare 的免费 SSL 证书进行管理。使用 nginx 配置服务器。

一切都很好,但突然我的服务器返回 403 响应。结果,我的 API 停止工作。

我的 ngnixn 服务器代码:

server {
    index index.php index.html index.htm index.nginx-debian.html;

        server_name api.shajao.com;
    client_max_body_size 500M;
        underscores_in_headers on;
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
        proxy_pass http://shajao_server;

    proxy_pass_request_headers on;

    client_body_buffer_size    500M;
    client_max_body_size 500M;

        proxy_http_version 1.1;
    proxy_set_header Access-Control-Allow-Origin *;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;

        add_header 'Access-Control-Allow-Origin' '*';
        }

}

我的快速服务器 cors 设置:

var allowCrossDomain = function (req, res, next) {
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With, Accept');

    // intercept OPTIONS method
    if ('OPTIONS' === req.method) {
        res.sendStatus(200);
    } else {
        next();
    }
};
app.use(allowCrossDomain);

我的网址:www.shajao.com

【问题讨论】:

  • 你能在这里附上nodejs的错误代码吗?
  • 我没有看到任何错误...我添加了我的网站 url.. 你可以在控制台中看到 cors 问题,在网络中你会看到我的 api 返回 403。

标签: node.js express nginx cors cloudflare


【解决方案1】:

导致 cors 问题的 cloudflare 发生了一些事情。从 cloudflare 中删除了我的域并从 godaddy 管理了我的 dns,一切都开始工作而没有任何更改。不确定 cloudflare 方面发生了什么。如果有人能回答就更好了

【讨论】:

    猜你喜欢
    • 2021-06-21
    • 2020-10-07
    • 2021-04-10
    • 2020-07-07
    • 2018-08-06
    • 2018-08-20
    • 2018-06-16
    • 2020-09-15
    相关资源
    最近更新 更多