Home > Article > Backend Development > Nginx implements AJAX cross-domain requests
More: http://www.webyang.net/Html/web/article_135.html
This is how HTTP cross-domain requests are implemented in the latest W3C standard,
Cross-Origin Resource SharingThe specific operation method can be controlled through different entrances:
1. PHP code control:2. HTML header control:
- php
- header("Access-Control-Allow-Origin: *");
- ?>
3. nginx configuration:
- http-equiv="Access-Control-Allow-Origin"content="*">
saw on the Internet that someone would add three sentences to nginx.conf:
- location /{
- add_header Access-Control-Allow-Origin*;
- }
- #授权从other.subdomain.com的请求
- add_header 'Access-Control-Allow-Origin''http://other.subdomain.com';
- #当该标志为真时,响应于该请求是否可以被暴露
- add_header 'Access-Control-Allow-Credentials''true';
- #指定请求的方法,可以是GET,POST等
- add_header 'Access-Control-Allow-Methods''GET';
But I tested it myself and it’s not necessary. In addition, if you want to specify a specific domain name, just modify *, which is usually the second-level domain name of an open site.
The above introduces Nginx to implement AJAX cross-domain requests, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.