Introduction
Websites generally set the access-control-allow-origin HTTP header only when they need to share resources with other websites (transfer data across origins)
Setting Access-Control-Allow-Origin can solve cross-origin issues with multiple domainsAccess-Control-Allow-Origin * means all websites can access cross-originAccess-Control-Allow-Origin gqink.cn allows gqink.cn to access cross-origin
Apache
<IfModule mod_headers.c>Header set Access-Control-Allow-Origin: "*" Header set Access-Control-Allow-Methods: "GET,POST,PUT,DELETE,OPTIONS" Header set Access-Control-Allow-Headers: "Content-Type"
</IfModule>
Add to the bottom of httpd.conf
NGINX
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'PUT,POST,GET,DELETE,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type,Content-Length, Authorization, Accept,X-Requested-With';
Or
location / { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"; add_header Access-Control-Allow-Methods "GET, POST, OPTIONS"; }
Add the code to NGINX
HTML
<meta http-equiv="Access-Control-Allow-Origin" content="*" />
Java
response.setHeader("Access-Control-Allow-Origin", "*");
.net
Response.AddHeader("Access-Control-Allow-Origin", "*");