解決nginx反向代理webservice的soap:address location問題


原文: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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM