问题
I am working on a server with nodejs the server is running on a VPS I hire. From the localhost on my pc, I send a request to the server but all it gives me back is:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8086' is therefore not allowed access.
But I have this in my default file in de Nginx configuration:
location / {
proxy_set_header 'Access-Control-Allow-Origin' '*';
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_redirect off;
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;
}
And here is an Access-Control-Allow-Origin header present so whats the problem here.
As always thanks for helping!
回答1:
It was a mistake in my nodejs code I didnt know that I needed to include
response.setHeader('Access-Control-Allow-Origin', '*');
来源:https://stackoverflow.com/questions/47488382/cors-with-reverse-proxy-nginx-server-and-nodejs-wont-work