1. Configuring Access URLs in nginx.conf
When you access api1.yingtrader.com/boquote, the boquote.php code is executed.
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/82/3A/wKiom1dOs3XisFbWAAD-ptQhK4g266.png "title=" Picture 10.png "alt=" Wkiom1dos3xisfbwaad-ptqhk4g266.png "/>
2. Nginx to implement AJAX cross-domain requests
To enable cross-domain requests on Nginx , you need to add the add_header access-control* directive.
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 ' POST, GET, OPTIONS, PUT, DELETE, HEAD ';
...
...
The rest of your configuration here
...
...
}
Comments are as follows:
First instruction: Authorizing requests from other.subdomain.com
Second instruction: When the flag is true, responds to whether the request can be exposed
The third day directive: Specifies the method of the request, which can be get,POST , etc.
If you need to allow access from any domain, you can configure this:
Add_header ' Access-control-allow-origin ' *;
Reference: http://www.ttlsa.com/nginx/how-to-allow-cross-domain-ajax-requests-on-nginx/
3. writing the PHP code
⑴ get POST parameters via $_post
Error_reporting (e_all^e_notice^e_warning);
... .. ... ..
$login = $_post[' UserAccount ');
$volume = $_post[' volume ');
... .. ... ..
⑵ return JSON data
... .. ... ..
$ret = Array ();
if (' OK ' = = $resarr [0]) {
$ret = [' success ' = ' tradesuccess '];
}else{
$ret = [' Error ' = ' tradefail '];
}
echo Json_encode ($ret);
This article is from the "Programming Art" blog, so be sure to keep this source http://itsart.blog.51cto.com/1005243/1785263
openresty+yii2.0 development of high Performance RESTFULAPI Series 3: Developing PHP-based RESTFULAPI