/dms

Primary LanguageShell

Docker management system

Never delete empty-docker-compose.yml! Its presence is necessary to build relative paths due to the following issue: docker/compose#3874

What is it?

This project is a ready to use infrastructure for your web server, mainly oriented to PHP projects. It was originally developed for our company needs. Default php containers are optimised for 1C Bitrix CMS.

The system consists of two parts: demo and prod.

Each part has a separate database server. There is a phpmyadmin container that has access to both database servers.

Demo and prod parts are exactly the same. They both have:

  • 2 web server containers, one with php 5.6, another with php 7.0
  • their own projects
  • their own configuration files

How it works?

There is a container with an nginx proxy server that handles the request first. If the required server name matches any from its configuration files nginx redirects the request to the web server container as specified in the configuration file.

Example:

server {
	listen 80;
	server_name example.ru www.example.ru;

	location / {
		proxy_pass http://demo_php7_web;
	}
}

There is a bundle of apache2 and nginx running into each web server container. Nginx receives the request first. The request will be handled by nginx if static assets are requested or passed to apache otherwise.

Features

  • There is a cron task to watch apache2 and nginx conf files. If changes are detected, the web server gets reloaded. Cron check period is 1 minute. So, if you changed a conf file, wait a minute for it to reload.
  • Every web server container has a "developer" user
  • Cron, Apache2 and Nginx run under "developer" user
  • SSL support. Check exmaple_ssl and example_ssl.conf in example_hosts.
  • Server side files compression configured
  • Installed: curl, rsyslog, htop, xvfb, libfontconfig, wkhtmltopdf, jpegoptim, optipng

Project structure

  • bin - put your binaries in here. Gets mounted to web server containers.
  • db_interface - contains conf file and docker-compose for phpmyadmin
  • demo - check demo section bellow
  • exmaple_hosts - example configuration files for nginx, apache2 and nginx proxy
  • prod - check prod section bellow
  • proxy - check proxy section bellow

Demo

  • apache2-nginx-php5.6 container
  • apache2-nginx-php7.0 container
  • database
  • hosts - contains configuration files for apache2 and nginx. These files run across web server container within demo part.
  • www - should contain folders with your projects. A project folder should have 'data' folder and 'logs' folder. Put your project files in data.

Prod

Has exactly the same structure and logic as demo part.

Proxy

  • certs - put your ssl related file into this folder
  • conf - contains nginx configuration file
  • cron - has a crontab to reload nginx proxy if any conf changes have been found
  • docker - Dockerfile and docker-compose
  • sites-enabled - put your sites configuration here for nginx proxy. Check example_hosts

Usage

When configuring the system in production you might need to use SSL, check example_ssl and example_ssl.conf in example_hosts.
Remember to configure proxy with SSL too. Check proxy/example_ssl in example_hosts.
If you're having troubles configuring the system for production, contact me by email: serkyron@gmail.com

Follow these steps to start using the system for local development. Create your 'example' host.

  1. git clone this repository
  2. ./build.sh
  3. cd demo/hosts
  4. put 'example.conf' file in to sites-enabled-apache with the following content:
    	Listen 8080
    
    	<VirtualHost *:8080>
    		ServerName example
    		ServerAlias www.example.ru
    
    		ServerAdmin webmaster@localhost
    		DocumentRoot /var/www/example/data
    
    		<Directory /var/www/example/data>
    		Allowoverride All
    	    </Directory>
    
    		ErrorLog /var/www/example/logs/apache.error.log
    		CustomLog /var/www/example/logs/apache.access.log combined_with_x_real_ip
    	</VirtualHost>
    
  5. put 'example' file in to sites-enabled-nginx with the following content:
    	server {
    		listen 80;
    		listen [::]:80;
    
    		server_name www.example.ru example;
    
    		root /var/www/example/data;
    		index index.php index.html;
    
    		# Add stdout logging
    
    		  error_log /dev/stdout info;
    		  access_log /dev/stdout;
    
    		  #error_page 404 /404.html;
    
    		  # redirect server error pages to the static page /50x.html
    		  #
    		  error_page 500 502 503 504 /50x.html;
    		  location = /50x.html {
    		    root /usr/share/nginx/html;
    		  }
    
    		  access_log /var/www/example/logs/nginx.access.log combined_with_x_real_ip;
    		  error_log /var/www/example/logs/nginx.error.log;
    
    		   location / {
    		      proxy_pass          http://localhost:8080/;
    		      proxy_set_header    Host           $host;
    		      proxy_set_header    X-Forwarded-For 82.202.249.25;
    		      proxy_redirect      off;
    		   }
    
    		   location ~*^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js|html)$ {
    		      root   /var/www/example/data;
    		      add_header Source nginx; 
    		   }
    	}
    
  6. cd .. (go back to demo folder)
  7. cd www
  8. mkdir example
  9. cd exmaple
  10. mkdir data
  11. mkdir logs
  12. echo "" > data/index.php
  13. cd ../../../proxy/sites-enabled/
  14. create 'example' file with the following content:
    	server {
    		listen 80;
    
    		server_name example example.ru www.example.ru;
    
    		location / {
    			proxy_pass http://demo_php7_web;
    		}
    	}		
    
  15. cd ../../
  16. ./run.sh
  17. Add '127.0.0.1 example' entry to your /etc/hosts file.
  18. Open http://example in browser