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