In-depth analysis of Nginx cross-origin AJAX requests, nginxajax

Source: Internet
Author: User
Tags subdomain

In-depth analysis of Nginx cross-origin AJAX requests, nginxajax

Cross-origin occurs when AJAX requests from one domain to another. So how can I implement ajax cross-origin requests on nginx? To enable cross-origin requests on nginx, add the add_header Access-Control * command. As follows:

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 ......}

Note:

First Command: authorize requests from other.subdomain.com

Second command: when the flag is true, the response is to whether the request can be exposed.

The third day command: Specifies the request method, which can be GET or POST.

If you want to allow access from any domain, you can configure it as follows:

Access-Control-Allow-Origin :*

Restart nginx

Service nginx reload

Ajax cross-origin request test

When the request is successful, the response header is as follows:

HTTP/1.1 200 OKServer: nginxAccess-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.