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
Related
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
When writing configuration files for Apache web server I would like to have a quick feedback loop.
I, for example have a script that doesn't seem to work. It is either not picked up, or the variables I use are not set, or maybe overriding is not allowed. How to debug this?
I expected to at least print some debug log statements like REQUEST_URI: %{REQUEST_URI}. Can't find such a thing.
apachectl is a front end to the Apache HyperText Transfer Protocol (HTTP) server. It is designed to help the administrator control the functioning of the Apache httpd daemon.
Here is a link to the documentation.
Different platform might use different binary names such as apache, apache2 or apache2ctl. To test the configuration - just run:
apachectl configtest
# or, depending on your OS
httpd -t
EDIT
If you are trying to debug your virtual host configuration, you may find the Apache -S command line switch useful. That is, type the following command:
httpd -S
This command will dump out a description of how Apache parsed the configuration file
I need to create an apache server to host my files and to get them by ajax. So, I'm using docker to deploy my server.
My docker image is httpd:2.4.
I deployed the server with the following command :
docker run -p 80:80 -dit --name file-server \
-v /sources/docker/apache-server/www/:/usr/local/apache2/htdocs/ httpd:2.4
But when I want to make the request for ajax, this is the result:
XMLHttpRequest cannot load http://server/kml/example.kml. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access.
So, I want to follow the next steps How to Enable CORS for Apache httpd server? (Step-By-Step Process). But I do not know how to add that command in the httpd.conf of the component. And I don't have the httpd.conf template to replace it with:
v /sources/docker/apache-server/my-httpd.conf:/usr/local/apache2/conf/httpd.conf
Please help me with this question.
You have that enter in shell-terminal with command docker exec -it nameContainer sh . write in terminal: su with those commands now you are root user in your Docker.
Now in terminal, you have than write a2enmod headers and restart your docker
The last command was for activate mod_header and just now you have that create a .htaccess in your project root file and write inside:
Header add Access-Control-Allow-Origin "*"
With that for me work fine and didn't need install apache in my machine
This has certainly already been addressed elsewhere and has many different solutions, however it's the first search hit for 'cors apache docker' so here's my 2 cents:
The best solution (because it is auditable and repeatable) is to use the apache docker image as a base for your own image using the docker build command and a Dockerfile. I won't go in to that as that's not the direct question here, but the basic bits are the same.
Create an "extra" apache config file with the CORS header bits:
me#mymachine:~$ docker exec file-server bash -c 'printf "<Directory \"/var/www/html\">\n Header set Access-Control-Allow-Origin \"*\"\n</Directory>\n" >> /usr/local/apache2/conf/httpd.conf'
me#mymachine:~$ docker exec file-server bash -c 'tail /usr/local/apache2/conf/extra/cors.conf'
<Directory "/var/www/html">
Header set Access-Control-Allow-Origin "*"
</Directory>
Restart apache to use this new config:
me#mymachine:~$ docker exec file-server bash -c 'apachectl -k restart'
NOTE: If you haven't configured a ServerName anywhere, then you might see this warning which is unrelated to the CORS configuration:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
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.
I need to enable mod_rewrite on a Apache server version 2.4.16. The server is running CENTOS 6.7 x86_64 - I tried many different things but nothing worked.
Also, is there anyway I can find out if mod_rewrite is already enabled?
Thanks,
Richard.
A good way to see if it's enabled is by trying to use it.
The apache documentation shows a pretty simple way to test out mod_rewrite . Place the following in an htaccess file:
Redirect "/foo.html" "/bar.html"
And then check if yoursite.com/foo.html redirects properly.
https://httpd.apache.org/docs/2.4/rewrite/remapping.html
a2ensite is not going to work, that's a binary built into the apache package for debian, you mentioned a centos installation.
To determine specifically if mod_rewrite is built into your apache install, use
httpd -M
To list loaded modules and grep for the one you want (rewrite).
[root#server ~]# /usr/sbin/httpd -M | grep rewrite
rewrite_module (shared)
[root#server ~]#
Test 1:
Easiest way to test if mod_rewrite is ON/OFF is to create a php info file
Under “apache2handler” check for “Loaded Modules” section. There will be a list of loaded modules. Check if mod_rewrite is present in the list.
Test 2:
By creating a file called .htaccess and then by typing the following lines in it
Options +FollowSymLinks
RewriteEngine On
How to find if mod_rewrite is enabled in Apache server?
Try with the command:
sudo a2enmod mod_rewrite