小编Raj*_*rth的帖子

Cors nginx 和 nodejs

我在客户端使用 ReactJS,在后端使用 NODEJS,使用 nginx 作为反向代理。我的 nginx 文件看起来像这样。

server{
            listen 80;
            server_name www.trusting.com;
            location / {

                    proxy_set_header 'Access-Control-Allow-Origin' 'http://localhost:3000';
                    proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
                    proxy_set_header 'Access-Control-Allow-Headers' 'X-Requested-With,Accept,Content-Type, Origin';

                    proxy_pass http://localhost:8080;
                    proxy_http_version 1.1;
                    proxy_set_header Upgrade $http_upgrade;
                    proxy_set_header Connection 'upgrade';
                    proxy_set_header Host $host;
                    proxy_cache_bypass $http_upgrade;





        }


    }
Run Code Online (Sandbox Code Playgroud)

即使认为在 nginx 上启用了 CORS,我在进行 REST 调用时在 ReactJS 端也会出错。

Failed to load http://www.trusting.com/hey/signup: Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.
Run Code Online (Sandbox Code Playgroud)

nginx node.js cors reactjs

1
推荐指数
1
解决办法
2373
查看次数

标签 统计

cors ×1

nginx ×1

node.js ×1

reactjs ×1