The solution to the invalid cross-domain setting Access-Control-Allow-Origin of Nginx
Nginx version 1.11.3
Using the following configuration, the verification is invalid and the cross-domain problem still exists
Add_header 'Access-Control-Allow-Origin'' *'; add_header 'Access-Control-Allow-Credentials'' true';add_header 'Access-Control-Allow-Methods'' GET,POST'
Use the following configuration to take effect.
If ($request_method = 'OPTIONS') {add_header' Access-Control-Allow-Origin''*'; add_header 'Access-Control-Allow-Methods'' GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers'' DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; add_header 'Access-Control-Max-Age' 1728000 Add_header 'Content-Type'' text/plain charset=UTF-8'; add_header 'Content-Length' 0; return 204;} if ($request_method =' POST') {add_header 'Access-Control-Allow-Origin'' *'; add_header 'Access-Control-Allow-Methods'' GET, POST, OPTIONS' Add_header 'Access-Control-Allow-Headers'' DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';} if ($request_method = 'GET') {add_header' Access-Control-Allow-Origin''*'; add_header 'Access-Control-Allow-Methods'' GET, POST, OPTIONS' Add_header 'Access-Control-Allow-Headers'' DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';}
Summary
The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.