swagger访问地址:http://xx.xx.xx.xx/tumor/swagger-ui.htmlhtml
界面能够正常被访问到,可是调用接口访问的地址倒是:http://127.0.0.1:10001/xx.xxx.xx等,说明swagger被nginx代理以后从http请求头中拿到的请求地址变成了nginx转发带过去的地址,并非真实的NGINX访问地址java
location /tumor {
proxy_pass http://127.0.0.1:10001/;
}nginx
有以下两种解决方案:
1.修改NGINX配置,重写请求头中的hostspring
在nginx配置中添加一行以下:app
location /tumor {ui
proxy_set_header Host $host:$server_port; #这一行就是来解决问题的,将NGINX接收到请求头中的Host和端口继续往下传递
proxy_pass http://127.0.0.1:10001/;
}spa
2.swagger自身也考虑到这种问题,所以能够增长配置来解决此问题代理
方式1:在启动脚本中添加,如:java -jar -Xms300m -Xmx300m -Dspringfox.documentation.swagger.v2.host=xxx.xxx.xxx.xxx/tumor /home/acct/app/tumorhospital/tumorhospital-1.0-SNAPSHOT.jar --spring.profiles.active=onlineserver
注意:不要在ip或者域名以前加http,swagger会自动加上的htm
方式2:在application.yml或者application.properties中加配置