I want to enable gzip compression on tomcat6 for files larger than 2048 bytes. I therefore set the Connector:
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
compression="on"
compressionMinSize="2048"
compressableMimeType="text/html,text/xml,text/css,application/javascript,application/json"
/>
However, the compressionMinSize parameter does not seem to work. In the Response Header I always get:
Content-Encoding:gzip
even for small responses (e.g. request size 376B, content size 213B)
Am I missing something?
The compressionMinSize option is only present in Tomcat 7.0 and up. For Tomcat 6.0 you should use compression="2048" to achieve the same effect.
Related
testing server uses centos 7 and tomcat 9
originally, testing server tomcat use http, this tomcat contains 4 web apps: a.war, b.war, c.war and d.war, it works fine and its server.xml looks like:
<Connector
port="80"
protocol="HTTP/1.1"
connectionTimeout="60000"
keepAliveTimeout="15000"
maxKeepAliveRequests="-1"
maxThreads="1000"
minSpareThreads="200"
maxSpareThreads="300"
minProcessors="100"
maxProcessors="900"
acceptCount="1000"
enableLookups="false"
executor="tomcatThreadPool"
maxPostSize="-1"
compression="on"
compressionMinSize="1024"
redirectPort="443" />
then i tried to use https with self signed ssl via keytool:
<Connector
port="443"
protocol="HTTP/1.1"
minSpareThreads="5"
maxSpareThreads="75"
enableLookups="true"
disableUploadTimeout="true"
acceptCount="100"
maxThreads="200"
maxPostSize="-1"
scheme="https"
secure="true"
SSLEnabled="true"
clientAuth="false"
sslProtocol="TLS"
keystoreFile="/opt/test.keystore"
keystorePass="123456"/>
however, after login, my webapp always shows loading:
I checked the log and found that there was an exception nullpointerexception because request.getParameter('key') returns null(actually both request.getParameterMap() and request.getParameterNames() return empty), but from the browser network, this parameter has been sent.
sometimes there is no any error in the log, but my webapp still always shows loading.
for #1 above, when login success, a.war will send requests to b.war, c.war and d.war, the request parameters includes an array(has 85 items and each item contains 7 fields) and key.
if i remove the array from the request parameter, only keep the request parameter key, then there is no always shows loading in https.
after checked the tomcat documents, i tried to change protocol for https connector.
If i changed the protocol from HTTP/1.1 to org.apache.coyote.http11.Http11Nio2Protocol, then there is no any problem in https, and i can send the request parameter array too.
so i don't understand:
send request parameter array(has 85 items and each item contains 7 fields) and key in https with protocol HTTP/1.1 sometimes will cause request.getParameterMap(), request.getParameterNames() return empty and request.getParameter('key') return null
why if i remove request parameter array in https with protocol HTTP/1.1, then it works fine.
why there is no any problem in http with protocol HTTP/1.1
why using org.apache.coyote.http11.Http11Nio2Protocol in https can solve my problems.
I bound my tomcat server to a specific address of a VM it's running on in order to open it up to HTTP requests on port 8443 like thus.
<Connector port="8443" protocol="HTTP/1.1"
address="192.168.122.15"
connectionTimeout="20000"
redirectPort="8443" />
Now the server times out even if I set the start timeout timer to 600 seconds (10 minutes)
I tried the following:
https://jfrog.com/knowledge-base/tomcat-takes-forever-to-start-what-can-i-do/
Tomcat 7 times out during start up
Neither of these solutions work.
Please check connection port and redirection one, as you are trying to redirect to the same port you are binding:
<Connector port="8443" [....] redirectPort="8443" />
Regards.
I am using Tomcat 8.5 to host a WAR which is used for java REST services.
In my rest service, I create a connection and take a multi-part form data file from user, scan it using a scan engine and return the result. At the start, tomcat is running fine and giving a speed of almost 57-58 Mbps but degrades over time (degrades to nearly half in 5-8 min)
My setenv.bat file looks like this.
"set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx5120m -XX:MaxMetaspaceSize=512m -Xincgc -server""
JVM is using ParNewGC for garbage collection.
my server.xml file looks like this
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="100" minSpareThreads="8" maxSpareThreads="10" acceptorThreadCount="16" acceptCount="500"/>
<!--acceptCount :The maximum queue length for incoming connection requests when all possible request processing threads are in use. Any requests received when the queue is full will be refused. The default value is 100.
A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
-->
<Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" socket.rxBufSize="10000000" socket.txBufSize="3000000" socket.directBuffer="true" />
<!-- A "Connector" using the shared thread pool-->
As my response is completely dynamic. I am not using any type of caching. please help me with this issue.
It may be a error due to a large number of open tcp/ip connections .Try connecting with server for once and send data check for sockets when you see a performance degradation.
In windows, you can use netstat-an to check the open sockets.
I installed Tomcat on Windows Server. Locally, if you type localhost:8080 or 127.0.0.1:8080 everything is working properly.
I have also set:
<Connector
port="8080"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
address="0.0.0.0"
/>
But when I type its IP address or hostname (installation on AWS) is a bug:
This site can’t be reached
I also have an unlocked port in the firewall
Page by IP is not seen either locally or externally
Can you add address="your_ip_address" attribute on Connector tag .
You can type your ip_address or 0.0.0.0 so that from anywhere it can accessible.
If you are using AWS. Please check Security group for that instance, that has to modify 8080 port inbound rule to allow access for globally (0.0.0.0/0)
<Connector
port="8080"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
just enough. no need to mention address here.
now you can be browse your tomcat http://Public_IP:8080
Need Step-by-Step Overview for Compression on Tomcat 7 ... I've been at this for days. Particularly interested in compressing text/xml in response from a servlet, but would also like to test other compressions.
From my googling and reading, it seems like I only need to add a few lines to configure the http connector in server.xml (see below). But I'm checking on sites like webpagetest.org and not seeing any results (not even gzip in the response header). What more do I need? Filters? Use of GZip methods within my app? Specifying the servlet(s) for output compression in web.xml? I'll be more than happy to continue getting the details right and would be happy just now to be sure I know what all the necessary parts are.
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,application/xml,text/javascript,text/css" />
UPDATE. SOLVED ... see comments under accepted answer below.
Did you restart Tomcat after editing server.xml file ?
Did you check the logs (logs/catalina.out) to see if there is any error on server startup ? (ie. typo in the config files)
compression="on"
should work.
Maybe webpagetest.org doesn't support gzip compression. Why don't you use Chrome Developper Tools (F12, you can see headers in the Network tab) ? or Firefox Web Console (Ctrl+Shift+K) ?