为什么我会收到此错误?无法读取swagger json

我有一个使用swagger-ui在localhost中使用apache的API,以使文档工作良好。我最近将我的应用程序上传到了Nginx Web服务器,但出现了以下错误:无法从https://myserver/swagger/docs/api读取JSON。我昂首阔步的配置在https://github.com/alt3/cakephp-swagger

这是我的swagger.php

<?php
use Cake\Core\Configure;

return [
    'Swagger' => [
        'ui' => [
            'title' => 'Swagger','validator' => true,'api_selector' => true,'route' => '/swagger/','schemes' => ['http','https']
        ],'docs' => [
            'crawl' => Configure::read('debug'),'route' => '/swagger/docs/','cors' => [
                'access-control-allow-origin' => '*','access-Control-Allow-Methods' => 'GET,POST','access-Control-Allow-Headers' => 'X-Requested-With'
            ]
        ],'library' => [
            'api' => [
                'include' => ROOT . DS . 'src','exclude' => [
                    '/Editor/'
                ]
            ],'editor' => [
                'include' => [
                    ROOT . DS . 'src' . DS . 'Controller' . DS . 'AppController.php',ROOT . DS . 'src' . DS . 'Model',]
            ]
        ]
    ]
];*

我的appController.php

 <?php
    /**
    @SWG\Swagger(
        @SWG\Info(
            title="Api Rest",description="Teste",termsOfService="http://swagger.io/terms/",version="1.0.0"
        )
    )
    */

还有我的Nginx配置

server {
       listen         80;
       server_name    myServer;
       return         301 https://$host$request_uri;
}


server {
    listen         443 ssl ;
    server_name    myServer;
    root           /nginx/myServer/webroot;
    index          index.php index.html;
    charset utf-8;

add_header 'access-control-allow-origin' '*' always;
add_header 'access-Control-Allow-Credentials' 'true';
add_header 'access-Control-Allow-Methods' 'GET,POST,PUT,DELETE,OPTIONS,HEAD,PATCH';
add_header 'access-Control-Allow-Headers' '*';

    location / {
#   rewrite ^/(.*)$ /webroot/$1 break;
        try_files $uri $uri/ /index.php?q=$uri&$args;


     if ($request_method = 'OPTIONS') {
        add_header 'access-control-allow-origin' '*';
        #
        # Om nom nom cookies
        #
        add_header 'access-Control-Allow-Credentials' 'true';
        add_header 'access-Control-Allow-Methods' 'GET,PATCH';
        #
        # Custom headers and headers various browsers *should* be OK with but aren't
        #
        add_header 'access-Control-Allow-Headers' '*';
        #
        # Tell client that this pre-flight info is valid for 20 days
        #
        add_header 'access-Control-Max-Age' 1728000;
        #add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 200;
     }
     #if ($request_method = 'POST') {
     #   add_header 'access-control-allow-origin' '*';
     #   add_header 'access-Control-Allow-Credentials' 'true';
     #   add_header 'access-Control-Allow-Methods' 'GET,PATCH';
     #   add_header 'access-Control-Allow-Headers' '*';
     #}
     #if ($request_method = 'GET') {
        add_header 'access-control-allow-origin' '*';
        add_header 'access-Control-Allow-Credentials' 'true';
        add_header 'access-Control-Allow-Methods' 'GET,PATCH';
        add_header 'access-Control-Allow-Headers' '*';
     #}

#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;

    }

    location ~* \.php$ {
      fastcgi_pass example:8080;
      include         fastcgi_params;
      fastcgi_index index.php;
      fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
      #fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}
guolingkai2009 回答:为什么我会收到此错误?无法读取swagger json

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3144361.html

大家都在问