An in-depth analysis of nginx implementation of Ajax cross-domain request _ajax related

Source: Internet
Author: User
Tags subdomain

Ajax requests another domain from one domain to have cross-domain problems. So how do you implement the Ajax Cross-domain request on the Nginx? To enable Cross-domain requests on nginx, you need to add add_header access-control* directives. As shown below:

Location/{
add_header ' access-control-allow-origin ' http://other.subdomain.com ';
Add_header ' access-control-allow-credentials ' true;
Add_header ' access-control-allow-methods ' ' get ';
...
...
The rest of your configuration here
...
...
}

The comments are as follows:

First directive: authorizing requests from other.subdomain.com

Second instruction: When the flag is true, it responds to whether the request can be exposed

Third day directive: Specifies the method of the request, can be get,post, etc.

If you need to allow access from any domain, you can configure this:

Access-control-allow-origin: *

Restart Nginx

Service Nginx Reload

Ajax cross-domain request testing

When successful, the response header looks like this:

http/1.1 OK
Server:nginx
access-control-allow-origin:other.subdomain.com

Related Article

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.