REST API communication - Nginx / CORS
Hello,
I ran into a problem with CORS blocking HTTP requests. By default, CORS is disabled in Nginx.
On https://ubiq.co/tech-blog/enable-cors-nginx/, I read that CORS should be enabled by adding:
add_header Access-Control-Allow-Origin *;
This allows cross-domain requests in Nginx, across all websites.
I attach the nginx.conf file and the screen from the Chrome browser console, where I have a test page made.
Adding a header in nginx.conf did not help and I still get the error. After installing the "Allow CORS" plug-in to the browser, the requests are carried out correctly.
Is the error on the side of a misconfigured nginx file, or is the browser itself blocking the CORS request from being sent?
I am probably not the first to encounter this problem.
Regards,
Kacper
[attachment]nginx.jpg[/attachment][attachment]chrome.jpg[/attachment]
I ran into a problem with CORS blocking HTTP requests. By default, CORS is disabled in Nginx.
On https://ubiq.co/tech-blog/enable-cors-nginx/, I read that CORS should be enabled by adding:
add_header Access-Control-Allow-Origin *;
This allows cross-domain requests in Nginx, across all websites.
I attach the nginx.conf file and the screen from the Chrome browser console, where I have a test page made.
Adding a header in nginx.conf did not help and I still get the error. After installing the "Allow CORS" plug-in to the browser, the requests are carried out correctly.
Is the error on the side of a misconfigured nginx file, or is the browser itself blocking the CORS request from being sent?
I am probably not the first to encounter this problem.
Regards,
Kacper
[attachment]nginx.jpg[/attachment][attachment]chrome.jpg[/attachment]
Comments
I'm not sure if you have seen this recent post which also dealt with the topic of CORS:
https://www.plcnext-community.net/en/discussions-2-offcanvas/front-end-use-of-the-rest-api.html
Does the resolution described in that thread help in your case?
Thanks for submitting the post. I also made changes to the nginx.conf and nginx_ehmi_location.conf files. These changes did not help.
I cannot locate the SSL.conf file on the driver.
I am wondering about the influence of the SSL certificate on the solution of the CORS problem. How does uploading an SSL certificate eliminate the problem?
Regards,
Kacper
The problem has been resolved. I had to reconfigure the nginx.conf and nginx_ehmi_location.conf files according to what was presented in the posted post. In my case, no configuration with SSL certificates was required.
Regards,
Kacper