nginx转发webService接口问题记录

由于最近公司新弄了个测试环境,需要在里面部署执行机,但与之前的环境网络不通,需要使用nginx代理转发,中途遇到了一些问题在此记录一下

1.nginx配置问题

server{
        listen 8080;
        location / {
             proxy_pass http://ip:port;
             proxy_set_header Host ip:port; #必配,否则导致Location问题
        }
}

2.webService代理问题

配置好nginx后代码一直报错:HTTP传输错误:java.net.ConnectException:Connection timed out

但是在浏览器中访问webService接口、在Postman中调用都是正常的,搞了两天才解决,使用代理时需要在实现接口时绑定远程调用接口

String wsdlURL = "xxxx"; //要请求的URL地址 
...
MyService myService = serviceWebClient.getPort(MyService.class);
BindingProvider bindingProvider = (BindingProvider) myService;
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlURL);

参考文章:webservice之Http传输错误问题 - 走看看 (zoukankan.com)

postman测试WebService接口_小豆的编程世界...的博客-CSDN博客_postman测试webservice接口

猜你喜欢

转载自blog.csdn.net/y954227239/article/details/127285348