[英]Need help fixing my nginx server
My console looks like this 我的控制台看起来像这样
This is my nginx cors setup 这是我的nginx cors设置
add_header 'Access-Control-Allow-Origin' 'http://beloveddais.com';
add_header 'Access-Control-Allow_Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' 'http://beloveddais.com';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow_Credentials' 'true';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
proxy_redirect off;
proxy_pass http://localhost:5000;
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;
}
my node server looks like this 我的节点服务器看起来像这样
var allowCrossDomain = function(req, res, next) {
if('GET' == req.method){
res.header('Access-Control-Allow-Origin', 'http://beloveddais.com');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
}
if('POST' == req.method){
res.header('Access-Control-Allow-Origin', 'http://beloveddais.com');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
}
if('OPTIONS' == req.method){
res.header('Access-Control-Allow-Origin', 'http://beloveddias.com');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,PATCH,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
res.sendStatus(200);
}
next();
On my browser console I have been getting multiple headers, only one accepted. 在我的浏览器控制台上,我得到了多个标头,只有一个被接受。 How do I fix this?
我该如何解决? I really need someone to help me out.
我真的需要有人帮助我。
Access-Control-Allow-Origin
header should only contain one value as the allowed origin or you can use * to allow all origins. Access-Control-Allow-Origin
标头应仅包含一个值作为允许的来源,或者您可以使用*允许所有来源。
As @TarunLalwani commented, you are adding http://beloveddais.com
as a value to the Access-Control-Allow-Origin
header both in your NGINX configuration and in your code for the OPTIONS
requests: 正如@TarunLalwani所评论的那样,您要在NGINX配置和
OPTIONS
请求的代码中将http://beloveddais.com
作为值添加到Access-Control-Allow-Origin
标头中:
add_header 'Access-Control-Allow-Origin' 'http://beloveddais.com';
AND 和
res.header('Access-Control-Allow-Origin', 'http://beloveddias.com');
Remove one of them depending on your choice of design and it should be ok. 根据您对设计的选择,删除其中之一,应该没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.