一:首先来发布一个web service

package com.ws.service;  
  
public interface IUserService  
{  
    public String getUserName(String id);  
}


package com.ws.service;  
  
import javax.jws.WebMethod;  
import javax.jws.WebParam;  
import javax.jws.WebService;  
  
@WebService  
public class UserService implements IUserService  
{  
    @WebMethod  
    public String getUserName(@WebParam(name="id") String id)  
    {  
        return "User:" + id;  
    }  
}

 copy


package com.ws.service;  
  
import javax.xml.ws.Endpoint;  
  
public class Server  
{  
    public static void main(String[] args)  
    {  
        Endpoint.publish("http://0.0.0.0:6633/api/v1/user", new UserService());  
        System.out.println("ws startup ok on port " + 6633);  
    }  
}


ws的端口为6633

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



然后,nginx的配置如下:

upstream webservice {  
    server 192.168.10.95:6633;  
}  
server {  
    listen       6633;  
    location / {  
        proxy_pass http://webservice;  
    }  
}


nginx地址为:192.168.2.123


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

结果如下


这里的地址明显错误。


解决方法如下

nginx配置改为:

upstream webservice {  
    server 192.168.100.95:6633;  
}  
server {  
    listen       6633;  
    location / {  
                proxy_set_header Host $host:$server_port;  
        proxy_pass http://webservice;  
    }  
}


原因在于如果没有配置

proxy_set_header Host $host:$server_port;

则,nginx反向代理到后台,传的Host http头为


Host=webservice


没有登录不能评论