Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Windows 綜合教學 >> 關於 Windows

Windows 下 Apache 部署站點公網存取檔案載入不完整?修改 server.xml 協定解決

編輯:關於 Windows

在 Windows 環境安裝 Apache Tomcat 部署網站時,本機測試正常,但透過公網 IP 或域名存取時,JavaScript、CSS 等靜態資源載入不完整、功能缺失。這通常是因為預設連接器協定 org.apache.coyote.http11.Http11NioProtocol 在某些網路環境(如反向代理、負載平衡器、防火牆)下處理 Keep-Alive 或分塊傳輸編碼異常。將協定改為標準 HTTP/1.1 即可解決。

修改步驟

  1. 開啟 Tomcat 安裝目錄下 conf/server.xml。
  2. 尋找 <Connector port="8080" ... /> 區段。
  3. 將 protocol="org.apache.coyote.http11.Http11NioProtocol" 修改為 protocol="HTTP/1.1"。
  4. 儲存並重新啟動 Tomcat 服務。

修改前

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
           connectionTimeout="20000" redirectPort="8443" />

修改後

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000" redirectPort="8443" />

server.xml 修改前後對比

補充說明

  • HTTP/1.1 會使用 Tomcat 內建的 Http11Protocol(舊版 BIO)或 Http11NioProtocol(新版 NIO)自動選擇,相容性最佳。
  • 若仍有問題,可嘗試調整 connectionTimeout、maxThreads、compression 等參數。
  • 生產環境建議前置 Nginx/IIS 做反向代理,由前端處理靜態資源與 SSL 終結,Tomcat 僅處理動態請求。

此修改適用於 Tomcat 7/8/9 系列,快速解決公網存取靜態資源截斷問題。

Copyright © Windows教程網 All Rights Reserved