Nginx和tomcat跨域問題

來源:互聯網
上載者:User

標籤:跨域問題   nginx和tomcat   tomcat過濾器   nginx   機頂盒   

項目用途:機頂盒 Portal 

環境說明:

1、使用Nginx 1.8.1 載入靜態頁面 *.html,在靜態頁面上去調用服務介面;

2、Tomcat 6 附加元件目;

遇到問題:機頂盒訪問不了頁面,無法載入資料。

分析:

1、查看介面日誌,傳入與輸出資訊均正常;

2、抓包,分析資料顯示沒有問題。

Ajax 就是接收不到返回的資料資訊,找了很久這個問題,原來是跨域給攔截了。

流程,

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/89/3A/wKioL1gNo5qwmyP6AABRBQysXUo828.png-wh_500x0-wm_3-wmp_4-s_3217498546.png" title="流程圖" alt="wKioL1gNo5qwmyP6AABRBQysXUo828.png-wh_50" />

解決方案 1:

    修改tomcat設定檔tomcat/conf/web.xml,修改過濾器配置,添加:

    <filter>

        <filter-name>CorsFilter</filter-name>

        <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>

    </filter>

    <filter-mapping>

        <filter-name>CorsFilter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

注意:tomcat版本需要 在tomcat7.0.4 以上;


解決方案 2:

修改Nginx設定檔,這個沒有做驗證,在這裡不做詳細描述。


特別感謝 楊老師、錢老師 。



Nginx和tomcat跨域問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.