About cross-domain request static file configuration issues [Access-control-allow-origin]

Source: Internet
Author: User
Tags iis

When requesting some files under different domain names, for example: src= ' ******.svg '

Sometimes there's a hint.

Cross-origin requests have been blocked: the same-origin policy prohibits reading remote resources located at *. (Reason: CORS header is missing ' Access-control-allow-origin ').

Font from Origin ' have been blocked from loading by cross-origin Resource sharing Policy:no ' Access-control-allow-origin ' Header is present on the requested resource. Origin ' is therefore not allowed access.


This is because the server prohibits the different domain names on the file request, some pictures to prevent hotlinking is through this configuration to do;

How to separate this permission. That is, the configuration file allows access to certain domain names.

The following are examples of Apache Nginx and IIS respectively


①nginx

Open the configuration file, configure Eot|otf|ttf|woff|svg and other files, allow access to all domain names, of course, you can also replace * to allow access to the domain name;

Example: www.baidu.com

Location ~* \. (Eot|otf|ttf|woff|svg) $ {
Add_header Access-control-allow-origin *;
}

Restart Nginx test


②apache

First edit httpd.conf

Find this line.

#LoadModule Headers_module modules/mod_headers.so

Remove the # comment

LoadModule Headers_module modules/mod_headers.so

To open the Apache header information Custom module


Then add a row to the virtual host for the standalone resource domain name

Header Set Access-control-allow-origin *

Restart Apache trial


③iis7

Open IIS, select the project, select Feature View on the right

Iis->http response Header (top right) actions, add

Name: Access-control-allow-origin

Value: *

OK, restart IIS, try


That should be it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.