【问题标题】:Enabling gzip compression for Jboss为 Jboss 启用 gzip 压缩
【发布时间】:2024-01-21 03:29:01
【问题描述】:

如何为 Jboss 5.1.0 启用 gzip 压缩?

在tomcat http 连接器中对吗?我不记得这个文件存储在哪里,server.xml?

【问题讨论】:

    标签: http configuration jboss compression application-server


    【解决方案1】:

    编辑 jboss\server\default\deploy\jbossweb.sar\server.xml

    编辑:

    <Connector protocol="HTTP/1.1" port="8080" address="${jboss.bind.address}" 
               connectionTimeout="20000" redirectPort="8443" />
    

    更像这样:

    <Connector protocol="HTTP/1.1" port="8080" address="${jboss.bind.address}" compression="on" 
    compressableMimeType="text/html,text/xml,text/css,text/javascript, application/x-javascript,application/javascript" 
    connectionTimeout="20000" redirectPort="8443" />
    

    您可以参考连接器配置信息以获取更多详细信息,请参阅: http://tomcat.apache.org/tomcat-5.5-doc/config/http.html

    【讨论】:

      【解决方案2】:

      要在JBoss 7.1.1 中添加gzip 压缩,您可以编辑standalone/configuration/standalone.xml 并添加:

             ...
          </extensions>
      
          <system-properties>
              <property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION" value="on"/>
              <property name="org.apache.coyote.http11.Http11Protocol.COMPRESSION_MIME_TYPES" value="text/javascript,text/css,text/html"/>
          </system-properties>
      

      重新启动服务器并使用开发人员工具检查或在 HTTP 标头中检查是否已启用。

      【讨论】:

      • 你好@doonot 我已经在我的 jBoss EAP 6.1 上实现了这段代码,当我在本地服务器上工作时它运行良好。但是当我转移到实际的服务器环境时,这些变化并没有得到反映。我的服务器是 jBoss Server EAP 6.1,在 Linux 操作系统上运行。 *.com/users/569077/doonot
      • @doonot,我尝试了类似的方法,但没有奏效看起来我错过了它*.com/questions/41011480/…请帮助
      【解决方案3】:

      该文件位于 server.xml 下,您正确地说必须更新 http 连接器。

      以下链接是 tomcat 的信息,但同样适用于 JBoss,除了 server.xml 文件的位置。相信你需要更新deploy\jbossweb.sar\下的server.xml

      http://viralpatel.net/blogs/2008/11/enable-gzip-compression-in-tomcat.html

      【讨论】:

        【解决方案4】:

        在 Jboss EAP 7.0 中,这对我有用:

        编辑:Standalone.xml

        <subsystem xmlns="urn:jboss:domain:undertow:1.2">   <!-- SEARCH FOR THIS: urn:jboss:domain:undertow -->
          <buffer-cache name="default"/>  
          <server name="default-server">  
          <http-listener name="default" socket-binding="http"/>  
          <host name="default-host" alias="localhost">  
          (...)
        
          <!-- ADD THIS FOR GZIP COMPRESSION -->
          <filter-ref name="gzipFilter" predicate="exists['%{o,Content-Type}'] and regex[pattern='(?:application/javascript|text/css|text/html|text/xml|application/json)(;.*)?', value=%{o,Content-Type}, full-match=true]"/>  
          <!-- /GZIP COMPRESSION -->
        
          </host>  
          </server>  
        (...)  
          <filters>  
          (...)  
        
          <!-- ADD THIS FOR GZIP COMPRESSION -->
          <gzip name="gzipFilter"/>  
          <!-- /GZIP COMPRESSION -->
        
          </filters>  
        </subsystem>
        

        重启服务器

        【讨论】:

        • 这不适用于 EAP 7.0 上的域设置。