swagger的优快云介绍http://blog.youkuaiyun.com/wangnan9279/article/details/44541665
1,git clone https://github.com/swagger-api/swagger-ui.git
2,cd swagger-ui
3,git clone https://github.com/zircote/swagger-php.git
4,replace url = "http://kehao-swag.com/makeapi.php";
5,makeapi.php
<?php
error_reporting(0);
require("../swagger-php/vendor/autoload.php");
$site = isset($_GET['site']) ? $_GET['site'] : 'pyyx-api';
switch ($site) {
case 'pyyx-api':
$dir = '/opt/dev/kehao/new_pyyx/api';
break;
case 'yii':
$dir = '/opt/dev/kehao/yii/demos/blog/protected';
break;
}
header('Content-Type: application/json');
echo \Swagger\scan($dir);
?>
6,configure Nginx
# new configuration
server {
server_name kehao-swag.com;
root /opt/dev/kehao/swagger-ui/dist;
index index.php index.html;
access_log /var/log/nginx/tools.access_log main;
error_log /var/log/nginx/tools.error_log info;
location ~ \.php$ {
root /opt/dev/kehao/swagger-ui/dist;
include fastcgi_params;
fastcgi_pass unix:/run/shm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME /opt/dev/kehao/swagger-ui/dist$fastcgi_script_name;
fastcgi_index index.php;
}
}
server {
server_name kehao.yii.com;
root /opt/dev/kehao/yii/demos/blog;
try_files $uri $uri/index.html @fpm;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header Access-Control-Allow-Methods 'GET,POST,OPTIONS';
access_log /var/log/nginx/new_pyyx.access_log main;
error_log /var/log/nginx/new_pyyx.error_log info;
location @fpm {
internal;
include fastcgi_params;
fastcgi_pass unix:/run/shm/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME /opt/dev/kehao/yii/demos/blog/index.php;
}
}