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正常了

 

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