spring boot 使用 swagger ui 做接口文档,很是方便
本地测试都没有问题
将一个Spring boot工程部署到生产环境, 配置nginx:
server {
listen 80;
server_name quanke.name;
location / {
proxy_pass http://127.0.0.1:3101;
}
}
浏览器中访问: quanke.name, 选中某一接口点击try it out,显示:
No Content。
Request URL:
http://127.0.0.1:3101/test
而不是
http://quanke.name/test
通过朋友+搜索知道有两种方法解决此问题:
把
server {
listen 80;
server_name quanke.name;
location / {
proxy_pass http://127.0.0.1:3101;
}
}
修改为:
server {
listen 80;
server_name quanke.name;
location / {
proxy_pass http://127.0.0.1:3101;
proxy_set_header Host $host; # 指定host
}
}
Java 启动的时候指定 swagger.v2.host
:
-Dspringfox.documentation.swagger.v2.host=quanke.name
启动命令实例:
java -jar -Dspringfox.documentation.swagger.v2.host=quanke.name /data/app/quanke/api.jar
或者在配置文件(application.properties)中进行配置
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有