原文:https://blog.csdn.net/mn960mn/article/details/50716768
一:首先來發布一個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;
}
}
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