Hi there,
I have set up a load balancer with SSL termination. Behind this I have set up an Node Express server using NGinx as a reverse proxy to allow traffic from port 80 to redirect to my Express server running on port 4000. I have set this up using the NGINXConfig tool, config found here
When I visit the website on my frontend however (https://mydomain.net), the request to my express server (https://api.mydomain.net) is blocked by CORS, specifically:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Oddly, when I had this set up with HTTPS between my NGinx proxy and the loadbalancer (without SSL Termination on the load balancer) this worked fine and I did not see CORS errors.
I assume this is down to the /etc/nginx/nginxconfig.io/security.conf file created by the NGINXConfig tool and the fact that the connection goes from HTTPS to HTTP, however I do not know what the correct secure config here should be and was wondering if anyone could help out?
Thanks
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
There are a few things that I could suggest:
https://www.npmjs.com/package/cors-anywhere
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
response.setHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");
Proxy Protocol for your Load Balancer.Let me know how it goes. Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.