PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

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

原创
2016-07-29 09:02:31 2949浏览

一:首先来发布一个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反响代理web service的soap:address location问题

然后,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反响代理web service的soap:address location问题

这里的地址明显错误。

解决方法如下

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

以上就介绍了解决nginx反响代理web service的soap:address location问题,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。