nginx修改webservice的WSDL

 

原项目的webservice,使用的是标准的http协议,最近进行安全检查,网站在负载均衡前面放置了证书完成了HTTPS改造,安全部门把目标盯在了还在用http协议传输的webservice接口。

网站改造了没问题,从HTTP、HTTPS协议上来看改成变更协议应该没问题,在webservice前端也放置了,证书,改走HTTPS协议,访问webservice地址,没有问题,执行报错了

查找错误原因,发现问题出现在wsdl身上

<s3:address location="http://api.padis.scwjxx.cn:80/server/LgProvinceService"/>

这段中的location还是使用的是http协议导致的问题,我将这个wsdl保存到本地,然后修改wsdl文件中的location部分为下面的内容:

<s3:address location="https://api.padis.scwjxx.cn:80/server/LgProvinceService"/>

然后使用本地的wsdl访问webservice服务,正常,那么现在问题能确认了就是wsdl的问题。

接下来该想如何解决了,之前做个一个类似的需求,当时使用的框架是spring cloud,在zuul里面讲response改写解决的,但是这个没有使用spring cloud的框架,无法使用zuul来解决了,考虑使用nginx来解决

道路是曲折的,过程是艰难的,结局是美好的。

下面来上最终配置

location / {
            root   html;
            index  index.html index.htm;
	    sub_filter http://api.padis.scwjxx.cn:80 "https://api.padis.scwjxx.cn:80";
	    sub_filter_once off;####所有匹配到的都替换
        }

        location /server {
	#proxy_set_header Host $host:$server_port;
	proxy_set_header Host $proxy_host;
	proxy_pass  http://api.padis.scwjxx.cn;
        proxy_redirect default;
            root   wsdl;
            #index  index.html index.htm;
	    #index  *.html
	    sub_filter http://api.padis.scwjxx.cn:80 "https://api.padis.scwjxx.cn:80";
	    sub_filter_once off;####所有匹配到的都替换
	    sub_filter_types text/xml; //关键
        }

然后简要说下踩坑过程,一开始我先配置了location /中的,修改了index.html如下:

<h1>Welcome to nginx!</h1>
<h1>"http://api.padis.scwjxx.cn:80/server/LgProvinceService"</h1>
<s3:address location="http://api.dis.scwjxx.cn:80/server/LgProvinceService"/>

这里的关键配置是sub_filter_once off;####所有匹配到的都替换,没有添加这个配置的时候,只替换了<h1>标签中的内容,添加了这个配置之后,完美,所有的都没问题了,实验结束,正式开始解决问题

        location /server {
	#proxy_set_header Host $host:$server_port;
	proxy_set_header Host $proxy_host;
	proxy_pass  http://api.padis.scwjxx.cn;
        proxy_redirect default;
            root   wsdl;
            #index  index.html index.htm;
	    #index  *.html
	    sub_filter http://api.padis.scwjxx.cn:80 "https://api.padis.scwjxx.cn:80";
	    sub_filter_once off;####所有匹配到的都替换
        }

按照实验进行了以下的参数调整,但是wsdl文件中的location内容没有变化,我一开始以为是root和index的问题,之前没有研究过nginx,后来看了文档发现跟这两兄弟没有关系,没有思路,继续读文档和sub_filter一起的是sub_filter_once和sub_filter_types,难道是sub_filter_types的问题,我观察了一下两次的请求的区别

第一次实验成功的html如下:

Connection: keep-alive
Content-Type: text/html
Date: Tue, 02 Apr 2019 03:33:59 GMT
Server: nginx/1.14.2
Transfer-Encoding: chunked

 

第二次解决问题的response如下:

Connection: keep-alive
Content-Type: text/xml;charset=utf-8
Date: Tue, 02 Apr 2019 03:50:04 GMT
Server: nginx/1.14.2
Transfer-Encoding: chunked

看出区别了吧,第一次的是text/html,第二次是text/xml,实话实说我一开始真没看出来,文档里写明了sub_filter_types默认是text/html,修改配置如下:

        location /server {
	#proxy_set_header Host $host:$server_port;
	proxy_set_header Host $proxy_host;
	proxy_pass  http://api.padis.scwjxx.cn;
        proxy_redirect default;
            root   wsdl;
            #index  index.html index.htm;
	    #index  *.html
	    sub_filter http://api.padis.scwjxx.cn:80 "https://api.padis.scwjxx.cn:80";
	    sub_filter_once off;####所有匹配到的都替换
	    sub_filter_types text/xml;
        }

重新实验,发现location已经变化,问题解决。

<s0:service name="LgProvinceServiceService">
<s0:port binding="s2:LgProvinceServiceSoapBinding" name="LgProvinceService">
<s3:address location="https://api.dis.scwjxx.cn:80/server/LgProvinceService"/>
</s0:port>
</s0:service>

wsdl正常,webservice正常了

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章