This image is an apache2 server prepared to serve multi domain environments. This is, hosts which serve multiple websites under different domain names.
This image is intended to be deployed in front of other web sites, application servers or any other service provided over the web via HTTP/HTTPS that are running on the same (or different) host(s) but you want to serve under different domains or subdomains.
This image exposes ports 80 and 443 to support both HTTP and HTTPS standard ports.
This image takes the following arguments:
- a server root volume
- a document root volume
- a log volume
This image provides simple mechanisms to add new sites, enable and disable sites. It provides 3 sample configurations:
- default: the default configuration that comes with apache HTTP server which serves as fallback for any request that was not mapped to a known site. The document root folder has been modified to serve content in /var/www/default
- foo: an HTTP site for foo.com serving contents from /var/www/foo
- bar: an HTTPS site for bar.com serving contents from /var/www/bar
- realbar: an HTTP site served via a reverse proxy from the real bar.com
To test the image:
-
Run it withour overriding configuration.
-
In your host machine edit
/etc/hostsand appendfoo.com,bar.comandrealbar.comsite to the line that maps your loopback interface to localhost:127.0.0.1 localhost foo.com bar.com realbar.com. -
Open a browser and try the following URLs:
http://localhost, you should see a welcome page indicating you are visiting the default site.http://foo.com, you should see a welcome page indicating you are visiting thhe foo site.http://bar.com, you should see a welcome page indicating you are visiting the default site. This is because bar site is only served over HTTPS.https://bar.com, now you should see the welcome page indicating you are visiting bar site.http://realbar.com, now you should see the realbar.comsite on the internet.
All sample commands assume that the container is run under the apache name.
This mode is only intended for you to check the correct instalation of the image. It will serve you to test the working samples.
docker run --name apache -p 80:80 -p 443:443 -d byteflair/httpd-multihostConfiguration (Server Root) and content (Content Root) volumes will be created and you will be able to manipulate configuration and content on the fly.
docker run --name apache -p 80:80 -p 443:443 -v /etc/apache2 -v /var/www -v /var/log/apache2 -d byteflair/httpd-multihostThe preferred way to run this image. Configuration (Server Root) and content (Content Root) volumes will be created at your specifiec location. You can also override the content of these volumes by specifying non empty folders. Maximun flexibility and convenience.
docker run --name apache -p 80:80 -p 443:443 -v /route-to-your-config:/etc/apache2 -v /route-to-your-content:/var/www -v /route-to-your-logs:/var/log/apache2 -d byteflair/httpd-multihostWhen following the instructions to add a new site, you will need to modify apache configuration files. Depending on how you run the container you will have to modify these files from within the container or from the host system via volumes.
In case you run the container without using volumes, files are not directly accessible from the host. We suggest you use docker cp to copy configuration files from the container to the host, make necessary modifications and copy them back to the container. Or you can connect to the container and run a bash terminal docker exec -ti apache bash and then edit or create the necessary files with vi.
If you choose to run the image using volumes but without mapping them to specific host folders, you will need to locate where those volumes are hosted. For example, issue the following command to know where the /etc/apache2 folder is hosted:
docker inspect -f '{{range $a := .Mounts}}{{if eq .Destination "/etc/apache2"}}{{.Source}}{{end}}{{end}}' apacheIf you run the image using explicitly mapped volumes, you can directly modify files from your mapped folders.
To add mysite.com and serve content from '/var/www/mysite.com':
- Copy
/etc/apache2/sites-available/000-default.confto/etc/apache2/sites-available/mysite.com.conf - Edit ServerName to match your desired domain name
mysite.com. - Edit the DocumentRoot to match the folder
/var/www/mysite.com. - Create the
/var/www/mysite.comfolder. - Add a sample HTML file on
/var/www/mysite.com. - Enable de new site as explained below
- Restart the container
- In your host machine edit
/etc/hostsand append your site to the line that mpas your loopback interface to localhost:127.0.0.1 localhost mysite.com - Open your browser and type:
http://mysite.com. Your sample HTML page should be served.
In this context we consider an application server any software capable serving dynamic content over HTTP/HTTPS.
In this case, our container will act as a reverse proxy and it will be your responsibility to provide the application server container or component.
To enable a site issue the following command:
docker exec apache a2ensite <site-name>Àfter enabling the site, you will need to restart the container for the changes to take effect.
docker restart apacheTo disable a site issue the following command:
docker exec apache a2dissite <site-name>Àfter disabling the site, you will need to restart the container for the changes to take effect.
docker restart apache