Httpd Example



Here in this example, we’ll be securing root directory, for that by setting the following in the httpd.conf file. Options None Order deny,allow Deny from all Options “None” – This option will not allow users to enable any optional features. Apache Httpd is basically a web server used for handling requests and delivering static content. While CGI is a protocol which adds a scripts with the request and based on the script the content is delivered instead of simply returning a static content. I have downloaded the standard httpd.conf file and enabled the necassary modules like modproxy, modssl etc. Download the httpd.conf file from here. Copy the Content from the aforementioned link and create a file named httpd.conf in the same Directory where the Dockerfile is located. Httpd configuration The examples web application deployed into Tomcat are published after installation by default on server-url:8080/examples. We will proxy requests coming to the server's port 80 (the default http port) requesting something from the server-url/examples to be served by the examples web application deployed into Tomcat.

Example Httpd.conf File For Apache

Introduction:

Linux - Failed To Start Httpd Server: Address Already In ...

In this post, we are going to see how to use docker httpd image and extend it to suit our needs and run the Apache web server as a Docker container.

We are also going to implement a docker reverse proxy as an additional example

Since we have targeted this post for Docker and Apache Installation and Configuration. We did not cover the fundamentals and basic components about Reverse Proxy but you can read, what is reverse proxy and how it is being configured in Traditional Apache Webserver in this link

I presume now you have understood what is Reverse Proxy and How it is working and configured in Traditonal and Normal Apache HTTPD Server environment.

Now let us move forward to the Docker Apache Image Creation and Reverse Proxy setup.

Steps Index:

  1. Choose the HTTPD Image from DockerHub (or) Optionally Download the image to Local
  2. Write Dockerfile and Use the Standard HTTPD image then Expand and Customize it.
    1. Create a Local httpd.conf file and Enable the modules you need
  3. Build and Create an Image using the Dockerfile
  4. Create Configuration and HTML files to feed the Container
    1. Create a WorkSpace
    2. Create two Directories named sites and htmlfiles to have conf and html files respectively
    3. Create Virtual Host configuration file *.conf under sites directory
    4. Create Html files under htmlfiles directory
  5. Start the Container from your Apache HTTPD Docker Image with Necassary Volumes and Port forwarding.
  6. Access the URL and Validate the Reverse Proxy

Step1: Choose the HTTPD Image from DockerHub (Download the Image)

Let us choose the Official Apache HTTPD Latest image and also download it to local using docker pull CLI command

in your master server where you are running the Docker Container Engine (CE) use the docker pull command like this

In fact, you do not have to explicitely mention the word latest here. If you just mention httpd the latest image would be picked up.

Note*: You can make sure the image is downloaded or not using the docker images CLI command

Step2: Dockerfile to Create a Customized HTTPD Image

Now there might be a question, Why can’t we use the httpd image as it is ?

The Answer is, The downloaded standard httpd image would have very minimal number of modules enabled. In order to implement reverse proxy we need to enable few modules like mod_proxy, mod_slotmem_shm, mod_watchdog etc.

Also, we need to enable the Support for our customized Virtual Host file and HTML files in the Container before we create it, Later during the startup time we can supply these (conf,html) files to the container

Here is the Docker file with self-descriptive comments for each line.

Step2a: Take the Standard httpd.conf file for apache2 and enable the modules you need

I have downloaded the standard httpd.conf file and enabled the necassary modules like mod_proxy, mod_ssl etc.

Copy the Content from the aforementioned link and create a file named httpd.conf in the same Directory where the Dockerfile is located.

If you look at our customized httpd.conf we have also added a Directive named IncludeOptional to add a directory of configuration where our Virtual Host conf files can be placed.

See more results

Any *.conf files placed in this directory would be considered by Apache HTTPD

If you scroll back and look at our Dockerfile once again you can see that we are creating this directory

So this sites directory is our Dedicated configuration files location where we can place our Virtual Host conf files

Step3: Build and Create an Image from the Dockerfile

In the Same Directory where our Dockerfile and httpd.conf file is present. Execute the following command

Now the Image is ready and available in your Local Images Repository and the image name is httpd-proxyenabled

Step4: Create the Configuration files and Directories( Virtual Host and Html files)

Now we are going to create our Virtual Host (A WebSite) configuration file and it will be loaded into the container when it is being started.

It is not recommended to Share a Single file between Container and the Local Server. You always can share a Directory as a volume between a Container and a Host.

Cached

So we are going to create two new directories to keep our HTML and Conf files respectively and we are going to mount these directories as a Volume inside the container.

Apache: sample-httpd.conf · GitHub

We will see how to do that in a minute.

Step 4a: Create a WorkSpace

Now choose some directory in your local system ( Mac/Windows) where Docker Container Engine is running and Let us call it as a workspace in my case it is /apps/docker/apacheconf

Step 4b: Create two Directories to place html and conf files

Create two Directories under the workspace to keep the virtualhost conf and html files.

Step 4c: Create Virtual Host configuration file under sites directory

Now go inside the sites directory and Create a Virtualhost configuration file ( A WebSite). If you have a Virtualhost file of your choice please use that or if you are following along, Please copy the following content and Save it as techolaf.conf

Step 4d: Create the html file under htmlfiles directory

Save the following content into a file named index.html under the htmlfiles directory

Step5: Start the docker httpd Container with Volumes and Port Forwarding

Volumes – is a Docker terminology, It helps you Mount the local file system [directory] inside the container as a volume

PortForwarding – Forward the Container Port to host

Here

--publish : to forward the container port 80 to Mac/Windows host’s port 90

-d : to run the container in background, Detached mode

--name: Name the container as apache server

-v : The Volume Mapping. Mounting the Host’s /apps/docker/apacheconf/sites as /usr/local/apache2/conf/sites inside the container

Now you can understand, that the directories we have created in local workspace are mounted inside the container and being used

In fact the Html and the configuration files we have placed in sites and htmlfiles directory on the local are now being used by the container and our website techolaf.com is ready

Note*: Before validating the Site. You need to be aware the ServerName specified in the configuration file is techolaf.com and Apache would look for this name on the Address bar when you try to reach the website.

In enterprise these things are managed with internal DNS servers. For testing you can use your /etc/hosts file

Make an entry in your /etc/hosts file like shown below

Apache Shows PHP Code Instead Of Executing It - Stack Overflow

127.0.0.1 www.techolaf.com

Now you are all set!.

Step6: Validate the Reverse Proxy

I hope you have your DNS records corrected.

Apache shows PHP code instead of executing it - Stack Overflow

With that assumption, let us go and hit the url

http://www.techolaf.com:90/ and http://www.techolaf.com:90/mwi

The Configured and Desired result is when you try with no URI (or) the Home URL you should get the welcome html page you have created and when you are using the URI mwi it should load the content of our www.middlewareinventory.com website home page.

The Home Page [ Welcome html ]

The Reverse proxy Page with URI

Mission Accomplished!

I know there are lot of steps in here. But if you follow along you can get it done very easily.

Try it and let me know if you get any issues and feel free to comment for any help or support

Rate this article [ratings]

MoreConf

See Full List On Hub.docker.com

Cheers,
Sarav AK

Follow us on Facebook or Twitter
For more practical videos and tutorials. Subscribe to our channel
Find me on Linkedin My Profile
For any Consultation or to hire us [email protected]
If you like this article. Show your Support! Buy me a Coffee.

Signup for Exclusive 'Subscriber-only' Content

More from Middleware Inventory

  • Apache Reverse Proxy - What is it and How to Configure Reverse Proxy

    Introduction Proxy, In general terms it means 'a person who is authorized to act for another'. In Server infrastructure, a Proxy Server do the same thing, It stands in for some other server, which should be kept away and hidden for so many reasons. Proxy servers are used for both legal…

  • Docker Run Image as Container - Create Container From Docker Image

    In this post, we are going to see how to create an image and run the image as a container and manage it. Before we proceed further, it is indispensable, that we are aware of what is an Image and What is a Container. So let us begin from there.…

  • Apache Webserver Basic Authentication using htpasswd - How to

    Overview To Secure the Apache Virtualhost (or) a particular document root /directory. We can use this Basic Auth mechanism. When the user is trying to access the resource from the directory. User will be prompted for Authentication. Step1 Create a Password file with username and password entry using htpasswd tool. Available…

  • Docker Weblogic : Run Oracle Weblogic 12c on Docker

    The Introduction to Docker Weblogic In this post, we are going to be exploring the quick and easy option available to get started with weblogic and Docker. In this post, we are going to see how to create a weblogic container in docker in a few easy steps. The post's…

  • Docker Tomcat Example - Dockerfile for Tomcat, Docker Tomcat Image

    In this post, we are going to learn how to install a Tomcat Application Server or Web Container on Docker and Deploy web applications into the Tomcat running inside Docker. This post is all about Docker Tomcat and deploying war web application into tomcat docker, Sample Docker Tomcat image, Dockerfile…