I want to enable gzip compression for an application that is served by an Apache instance running inside a Docker container. I'm using the httpd Alpine image as the base image for my Dockerfile.
I followed this post, enabled deflate_module and appended the shown code to my httpd.conf to only compress certain filetypes.
When I restart Apache with apachectl -k restart and open the served page, the content does not get gzipped (Content-Encoding Response Header is not set) although deflate_module get's loaded (checked with apachectl -M).
Am I missing an important step to enable the gzip compression?
Any help on this would be great!
Maybe you can enable compression using .htaccess
Look at this. Maybe you can take an idea from there.
Related
I've setup a httpd with docker:
FROM httpd:2.4-alpine
# load required modules (unfortunately gzip is not available)
RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf
RUN sed -i '/LoadModule deflate_module/s/^#//g' /usr/local/apache2/conf/httpd.conf
# AllowOverride All so that custom .htaccess is applied
RUN sed -i 's#AllowOverride [Nn]one#AllowOverride All#' /usr/local/apache2/conf/httpd.conf
Runs fine, but i need the mod_gzip module enabled which is not listed in httpd.conf
What i need to do in order to get the mod_gzip enabled in official docker httpd:2.4-alpine image?
Seems like mod_gzip is obsolete for apache 2.4 and mod_deflate is the way to go for doing the compression.
mod_deflate is integrated in the default apache package and just have to be enabled, mod_gzip remained external extension module and the integration is complex
I just installed a sole Apache 2.4 (without any other modules like Php or what else) and intended to host static files on it. The static files are placed under /var/www/html/test-files/. I tried to enable the core ContentDigest (documented by Apache2 at Apache2 Core) by two ways:
Create .htaccess under /var/www/html/test-files/ and added ContentDigest On to the file.
Edit /etc/apache2/apache2.conf and added following to it:
<Directory /var/www/html/test-files/>
ContentDigest On
</Directory>
I used Inspect feature of Google Chrome to test downloading some .html and mp4 files but couldn't see any Content-MD5 tag included in headers.
Note: all configs are default.
Do I mis-understand something here? How can I enable the tag?
I did solving the issue by using the second approach PLUS disabling mod_deflate:
sudo a2dismod deflate
sudo service apache2 restart
I am not sure when this started happening, but I have noticed that when I download .gz (gzip) files through httpd (apache 2.4.28), and try to open them on the client they are corrupted.
If I download them via sz, ftp, or another method they open fine on the client. If I transfer them via scp to another server and download them they work fine.
At first I thought it could be mod_deflate compressing it more than it should and corrupting it, but I disabled mod_deflate and the behavior still occurs.
I then downloaded nginx-1.12.2.tar.gz from nginx.org using wget on the server. When I downloaded that through Apache, it opened fine on the client.
As another test, I created a gz file on another server and transfered it over to the problematic one. Tried downloading that & it was corrupted.
So not really sure whats going on here. Can't seem to get a rhyme or reason to this bug.
Any thoughts?
Same problem here with apache 2.2 and 2.4, but removing
SetOutputFilter DEFLATE
from the vhosts configuration file (and doing an apache reload) fixed it for me on either machine.
Make sure to restart or at least reload apache after changing the vhosts config.
Turns out it was an incorrect mime type in the httpd.conf file.
I want to setup Apache and Glassfish on Ubuntu 16.04 server.
I have installed
apache2
libapache2-mod-jk
glassfish
The following are the steps I have followed
Configuring the MPM module
Set MaxRequestWorkers to 400 in /etc/apache2/mods-available/mpm_event.conf
Configuring the JK Module
<IfModule mod_jk.c>
JkWorkersFile /usr/share/glassfish4/glassfish/domains/<domain-doamin1>/config/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel error
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMountCopy all
</IfModule>
JkMount /myapp/* ajp13
<Location "/myapp/WEB-INF/">
require all denied
</Location>
Create a workers.properties file in your GlassFish domain's config directory
worker.list=ajp13
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
# load balancing only: worker.ajp13.lbfactor=50
connection_pool_size=10
connection_pool_timeout=600
worker.ajp13.socket_keepalive=False
worker.ajp13.socket_timeout=30
Create the JK listener in GlassFish using these commands
asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server jk-listener
asadmin set server-config.network-config.network-listeners.network-listener.jk-listener.jk-enabled=true
then I restarted glassfish domain successfully but when i try to restart apache2 with sudo /etc/init.d/apache2 restart I get the error below
[....] Restarting apache2 (via systemctl): apache2.serviceJob for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.
failed!
This error occurs when I edit the file jk.conf located under /etc/apache2/mods-available/jk.conf
Where am I going wrong. Is there a complete guide to accomplishing this? Finally the newer apache2 doesn't have the file httpd.conf and all the tutorials allover the Internet rely upon this file. Thanks in advance.
Since your objective is just to forward requests from Apache to GlassFish, not to loadbalance requests from Apache to multiple GlassFish servers, I would recommend avoiding mod_jk. You can certainly achieve your goal with it, but if you are new to the concepts involved, you will find it difficult to understand and maintain.
Instead you can use mod_proxy and, optionally, mod_proxy_ajp.
First, a definition:
AJP vs HTTP
AJP is a protocol like HTTP, but binary rather than text based. It has no secure/insecure options like HTTPS/HTTP since it is normally used behind a firewall and performs much better than HTTP for these scenarios. When you mark any GlassFish network listener as jk-enabled, you are enabling AJP communication, rather than HTTP.
You've installed Apache via the ubuntu apache2 package which has its own example structure to configuration which is different to the layout you would get if you downloaded and unzipped it. This has advantages, but we need to understand the Apache configuration file before getting to that.
Apache Configuration
Generally, you will see internet guides refer to httpd.conf as the configuration file to edit. This is just the default "parent" configuration file. In Debian/Ubuntu systems (and their derivations, like Linux Mint), the file to look for is apache2.conf.
This file is read, and its directives applied, from top to bottom, so if you have set the same property to two different values, the second will apply. (More accurately, they will both apply but the first will only apply until the second setting is read).
This file can also specifically "include" files and folders (where any *.conf file in an included folder will be included). These will be read in and merged with the main configuration at the point where the "include" statement is written. So the very last line in the main configuration file (if it is not specifying another file) will be the last line of configuration to be set, no matter what.
Debian config layout
I would highly recommend you read the opening comment in the apache2.conf file, since it will tell you all you need to know about the layout. Suffice it to say that keeping all the config in one file is very painful to maintain. The Debian package separates configuration into three categories:
sites
Sites are single configuration files for a website or web project. This could be anything: PHP, static HTML or a Java EE application deployed to an app server like GlassFish.
mods
Modules are subdivided into *.load files which load the actual libraries needed to run them, and *.conf files which have global configuration for the modules. Note that this configuration applies to every site that uses the module, so it is best to put any site/app specific module configuration in the appropriate site.conf file
conf
These files are just for any other general configuration which fits into a nice group. This could be SSL configuration like keystore and truststore locations.
When you look at the directory structure, you will see that each of these have 2 folders: *-available and *-enabled. This is because the Debian Apache package comes with 6 helper tools, a2ensite and a2dissite; a2enmod and a2dismod; a2enconf and a2disconf. The idea is that you follow these rules:
Never directly edit the apache2.conf file
only ever add or change files in the *-available folders
Use the helper tools to enable or disable sites/modules/conf files.
Answer
So to (finally) answer your question, I would do the following steps:
Enable mod_proxy_ajp
a2enmod mod_proxy_ajp
Create a new myApp.conf in sites-available. You can copy the default one, which is a good example. Assuming you have just want to forward all requests to GlassFish, you can use the default VirtualHost settings of ` which will process a request for any hostname on port 80. Use port 443 if you want to add HTTPS.
Add ProxyPass and ProxyPassReverse directives to the location of your server. If Apache and GlassFish are on the same server, it is likely you will want to use ajp://localhost:8080
ProxyPass / ajp://host_name:0000
ProxyPassReverse / ajp://host_name:0000
Note: This assumes you are using AJP. If that causes you problems, switch to HTTP by changing ajp to http above and disabling the jk-listener in GlassFish.
Once you have completed your myApp.conf configuration, remember to disable the default site:
a2dissite 000-default-site.conf
And enable your new site:
a2ensite myApp.conf
Those commands will appropriately modify the main apache2.conf and create the appropriate links in the sites-enabled folder.
That should be all you need. Now, everything that points to your hostname after the root / of the URL will be forwarded to the root context / of GlassFish.
How can I get mod_deflate on Apache and Heroku Cedar with a PHP app? I have mod_deflate importing and rules set set in my htaccess, yet my responses won't gzip.
Not sure if you're still interested in solving this problem, but here goes. A lot of this is going to depend on how you've set your dyno up.
If you're running the Heroku PHP buildpack with Apache, the buildpack version of Apache comes with mod_deflate pre-installed.
Even if you're not running the Heroku PHP buildpack, there's some chance that mod_deflate might be pre-installed. You can check by running a bash prompt on a one-off dyno and using apache2ctl to list all available modules:
$ heroku run bash
Running `bash` attached to terminal... up, run.9057
$ $(which apache2ctl || which apachectl) -M
Loaded Modules:
core_module (static)
...
deflate_module (shared)
...
After ensuring that mod_deflate was installed and enabled, I then used the .htacess configuration recommended by html5-boilerplate to compress textual MIME types. I added this config to my apache config, but I would think it would work from .htaccess too. After deploying the new configuration, mod_deflate worked as expected.
Hope this helps!