If you've heard about Docker, you may know about its ability to help you build applications in a sealed environment. This is helpful, as it eliminates any changes that may occur between your developer machine and your production machine, such as a VPS server from Hostwinds.
How To Install Docker
Install docker using this command:
apt-get install docker
Container technology is beneficial in sealing an environment, but when you need to configure things like SSL or other applications, this can introduce additional complexity.
Nginx (Pronounced "Engine-ex") is a highly configurable web server. This makes it great for things setting up what's called a "reverse proxy," which simply means that this webserver will take in requests and forward them to our Docker containers. Add this into your Hostwinds VPS with:
apt-get install nginx
Setting up a simple Apache Container
For this, We're going to use the official Apache image on the Docker hub. It's documentation can be found here.
As the documentation mentions, we will need to create a DockerFile.
Using a text editor, such as nano (nano apache. docker), write a file with these contents:
COPY ./index.html /usr/local/apache2/htdocs/
Now create a file called index.html, and insert this into its contents:
<h1> Hello World! </h1>
It is possible to use any static page or even a directory in place of the index file. For simplicity, a single HTML file is fine. Once the file is written, run these commands to build the docker file.
docker build -t apache-demo
docker run -dit --name demo-web -p 8080:80 apache-demo
Visiting your server at [yourdomain:8080] or [your IP]:8080 Should result in seeing this page in your web browser
Configuring Nginx as a reverse proxy
With the docker container set up to serve your files, we can set up Nginx. This way, we can mostly leave the container's configuration alone and silo it off behind Nginx. Edit /etc/nginx/nginx.conf and add in this code: