Giter VIP home page Giter VIP logo

quick-vhost's Introduction

quick-vhost

A simple bash script to quickly create a virtual host config file for Apache and Nginx. Also, creates the main document root and a static document root (public sub directory) served by Nginx directly.

This script was created for a very specific purpose, but could probably be easily configured for other purposes. The setup it's intended for is a host computer serving multiple PHP websites through Apache running inside of a Docker container and using Nginx to route requests. It also automatically creates a static subdomain that can be used for bypassing Apache for static content.

SETUP

Simply edit the configuration directories at the top of the main .sh file and customize the templates in the template directory as needed.

EXAMPLE USAGE

./quick-vhost.sh itslennysfault.com
Creating apache vhost conf
Creating apache nginx conf
Creating apache document root
Creating static document root
Creating placeholder indexes

This would create the following files / directories in the default configuration:

  • /var/www/vhosts/itslennysfault.com.conf
    • Apache config file for the virtual host itslennysfault.com pointing to the document root of the same name
  • /etc/nginx/sites-enabled/itslennysfault.com
    • Nginx config file for the virtual host itslennysfault.com that proxies to apache running inside of a docker container AND static.itslennysfault.com pointing to the public sub folder of that same document root allowing nginx to serve static files from that subdomain
  • /etc/httpd/vhosts/itslennysfault.com
    • Apache document root
  • /etc/httpd/vhosts/itslennysfault.com/public
    • Nginx static document root
  • also creates a placeholder index.html in both of the document roots.

CONFIGURATION

HOST_DOCUMENT_DIR This is the path where the script will create the document root for this virtual host. This is also the path used in the Nginx config so it knows where to look for static files.
CONTAINER_DOCUMENT_DIR This is the path that will get set in the apache virtual host. If your host and container are using the same file paths OR if you're running Nginx and Apache on the same server/container this would be the same as the above. However, often you're mapping a volume on the container to a different path on the host.
APACHE_VHOST_DIR This is the directory on the host where the virtual host configurations will be stored. This should be mapped to a directory inside of the container that is included in the apache config.
NGINX_VHOST_DIR This is the directory where you want the virtual host configuration files for Nginx to be stored. This could be your sites-enabled directory, but it's probably better to create a separate directory for these files and set them to be included automatically.

EXAMPLE SETUP

Below is everything needed to get up and running with a container-ized Apache instance running behind Nginx. There are more optimal ways to initiate this, but this is the quickest way to get up and running. It is assumed you already know how to create a docker container running Apache.

Quick-Vhost Configuration:

HOST_DOCUMENT_DIR="/ilf/docroots/"
CONTAINER_DOCUMENT_DIR="/var/www/vhosts/"
APACHE_VHOST_DIR="/ilf/apache-vhosts/"
NGINX_VHOST_DIR="/ilf/nginx-vhosts/"

Apache Configuration (within container):

#includes files generated by quick-vhost
Include vhost/*.conf

Nginx Configuration:

#includes files generated by quick-vhost
include /ilf/nginx-vhosts/*;

Map volumes on docker to appropriate paths on the host:

docker run -v /ilf/apache-vhosts:/etc/httpd/vhost -v /ilf/docroots:/var/www/vhosts -p 8080:80 ilf_php2 /usr/sbin/httpd -D FOREGROUND &

quick-vhost's People

Contributors

itslenny avatar

Stargazers

Chris Weiss avatar Toan Ha avatar  avatar  avatar Rubén González avatar  avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.