关于 Nginx 和 Swagger UI 的问题 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
JasonLaw

关于 Nginx 和 Swagger UI 的问题

  •  
  •   JasonLaw 2021 年 11 月 3 日 2082 次点击
    这是一个创建于 1632 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我有个 web 应用,使用 Nginx 进行代理,Nginx 的配置如下(已简化):

    http { upstream appServerBackend { server localhost:8081; } server { listen 443 ssl http2; server_name a.com; location /appServer/ { proxy_pass http://appServerBackend/; } } } 

    web 应用使用 Swagger 产生文档,以下是 Swagger UI 展示的 Servers ,其值为http://appServerBackend:80,导致在 Swagger 执行请求时会请求http://appServerBackend:80,而不是期望的https://a.com/appServer。怎样操作才能实现“在 Swagger 执行请求时请求https://a.com/appServer”呢?


    尝试解决

    我尝试过修改 Nginx 的配置,在 proxy_pass 下面加上如下代码块。

    proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Host $host; 

    Servers 变成了https://a.com:443,还不是我期望的https://a.com/appServer,我应该怎么操作才能让 Servers 变成https://a.com/appServer呢?

    相关资料

    第 1 条附言    2021 年 11 月 3 日
    5 条回复    2021-11-03 19:04:30 +08:00
    litchinn
        1
    litchinn  
       2021 年 11 月 3 日
    应该是在 swagger 配置里改,Docket.host()
    JasonLaw
        2
    JasonLaw  
    OP
       2021 年 11 月 3 日
    @litchinn #1 使用 SWAGGER_2 时,设置 springfox.documentation.swagger.v2.host 为 a.com/appServer 就行了,但是 OAS_30 不行。
    neekeV2
        3
    neekeV2  
       2021 年 11 月 3 日
    同样问题,我是这么处理的。
    nginx:
    server {
    listen 80;
    server_tokens off;
    charset utf-8;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_comp_level 5;
    gzip_types text/plain application/Javascript application/x-Javascriptapplication/xml text/Javascript application/json text/css;
    location /api/ {

    proxy_pass http://127.0.0.1:10000/api/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    }
    springboot:

    server:
    port: 10000
    servlet:
    context-path: /api
    JasonLaw
        4
    JasonLaw  
    OP
       2021 年 11 月 3 日
    @neekeV2 #3 设置 server.servlet.context-path 为 /appServer ,然后做相应的修改,的确是可以。不过我不想设置 server.servlet.context-path。
    JasonLaw
        5
    JasonLaw  
    OP
       2021 年 11 月 3 日   1
    @litchinn #1
    @neekeV2 #3
    @ila

    找到解决方案了,请见附言。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     951 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8. 28ms UTC 22:01 PVG 06:01 LAX 15:01 JFK 18:01
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86