解决nginx反响代理web service的soap:address location问题

转自:https://blog.csdn.net/mn960mn/article/details/50716768

感谢作者整理

一:首先来发布一个web service

  1. package com.ws.service;
  2. public interface IUserService
  3. {
  4. public String getUserName(String id);
  5. }
  1. package com.ws.service;
  2. import javax.jws.WebMethod;
  3. import javax.jws.WebParam;
  4. import javax.jws.WebService;
  5. @WebService
  6. public class UserService implements IUserService
  7. {
  8. @WebMethod
  9. public String getUserName(@WebParam(name="id") String id)
  10. {
  11. return "User:" + id;
  12. }
  13. }
  1. package com.ws.service;
  2. import javax.xml.ws.Endpoint;
  3. public class Server
  4. {
  5. public static void main(String[] args)
  6. {
  7. Endpoint.publish( "http://0.0.0.0:6633/api/v1/user", new UserService());
  8. System.out.println( "ws startup ok on port " + 6633);
  9. }
  10. }

ws的端口为6633

访问地址为:http://192.168.100.95:6633/api/v1/user?wsdl



然后,nginx的配置如下:

  1. upstream webservice {
  2. server 192.168.10.95: 6633;
  3. }
  4. server {
  5. listen 6633;
  6. location / {
  7. proxy_pass http: //webservice;
  8. }
  9. }

nginx地址为:192.168.2.123

然后访问代理地址:http://192.168.2.123:6633/api/v1/user?wsdl

结果如下


这里的地址明显错误。


解决方法如下

nginx配置改为:

  1. upstream webservice {
  2. server 192.168 .100 .95: 6633;
  3. }
  4. server {
  5. listen 6633;
  6. location / {
  7. proxy_set_header Host $host:$server_port;
  8. proxy_pass http: //webservice;
  9. }
  10. }

原因在于如果没有配置

proxy_set_header Host $host:$server_port;
则,nginx反向代理到后台,传的Host http头为

Host=webservice

猜你喜欢

转载自blog.csdn.net/shulai123/article/details/80982177
今日推荐