【问题标题】:/swagger-ui/index.html not found/swagger-ui/index.html 未找到
【发布时间】:2018-07-25 18:01:12
【问题描述】:

我按照这里在 centos 7(使用 docker)中设置分离的前端和后端,使用 nginx 托管我的前端,我的网站工作,所有 /api/.... 请求工作,但是,当我想检查 swagger 服务的 RESTful API 时,出现 404 错误,fiddler 说:

not found /swagger-ui/index.html

我在主机上打开 8080 并浏览 swagger-ui 文件夹,index.html 就在那里。并且所有 www 文件夹都被授予 755 权限。

nginx site.conf 如下:

server {
    listen 80;
    index index.html;
    server_name localhost;
    error_log  /var/log/nginx/error.log;

    location / {
        root /usr/share/nginx/html;
    }
    location /api {
        proxy_pass http://www.example.com:8080/api;
    }
    location /management {
        proxy_pass http://www.example.com:8080/management;
    }
    location /v2 {
       proxy_pass http://www.example.com:8080/v2;
    }
    location /swagger-ui {
        proxy_pass http://www.example.com:8080/swagger-ui;
    }
    location /swagger-resources {
        proxy_pass http://www.example.com:8080/swagger-resources;
    }
}

怎么了?

================================更新 发布后:

sudo docker logs -f -t --tail 100 docker_nginx_1

发现日志文件有问题:

2018-07-14T17:35:40.904857522Z 187.67.50.246 - - [14/Jul/2018:17:35:40 +0000] "GET /cgi/common.cgi HTTP/1.1" 404 169 "-" "Wget(linux)" "-"
2018-07-14T17:35:40.904920067Z 2018/07/14 17:35:40 [error] 5#5: *23 open() "/usr/share/nginx/html/cgi/common.cgi" failed (2: No such file or directory), client:187.67.50.246, server: localhost, request: "GET /cgi/common.cgi HTTP/1.1", host: "39.107.246.223"
2018-07-14T17:35:43.896984659Z 187.67.50.246 - - [14/Jul/2018:17:35:43 +0000] "GET /stssys.htm HTTP/1.1" 404 169 "-" "Wget(linux)" "-"

【问题讨论】:

  • 只是在 /var/log/nginx 文件夹中找不到 error.log 文件,在 /var/lib/docker/ 中,找到了一个 xxx-json.log,它说:{"日志":"221.217.121.209 - - [14/Jul/2018:12:42:58 +0000] \"GET /swagger-ui/index.html HTTP/1.1\" 404 1302 \"sample.com\" \ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36\" \"-\"\n","stream":"stdout","时间":"2018-07-14T12:42:58.177129055Z"}
  • 您似乎没有启用调试模式。您是否尝试过注释掉所有其他位置并仅保留 /swagger-ui 和 /swagger-resources?您也可以尝试添加尾随 /
  • 怀疑是nginx配置相关的问题,docker-compose up后,文件夹/var/log/nginx和/usr/share/nginx不存在,我创建了这样两个文件夹,可以t nginx docker 自动创建这样的文件夹?还是我错过了什么?

标签: nginx jhipster


【解决方案1】:

在我注释掉之后就可以了:

location /swagger-ui {
    proxy_pass http://www.example.com:8080/swagger-ui;
}

我认为 swagger-ui 是由 nginx 而不是后端提供的。

【讨论】:

    猜你喜欢
    • 2020-09-14
    • 2018-02-03
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    相关资源
    最近更新 更多