Skip to content

NGINX Template: A docker image for web server, reverse proxy, load balancer, and HTTP cache with various features like rate limiting, HTTP/2, HTTPS, and more. Ideal for development and test environments.

License

Notifications You must be signed in to change notification settings

humblebeeintel/server.nginx-template

Repository files navigation

NGINX template

MIT License GitHub Workflow Status GitHub release (latest SemVer) Docker Image Version Docker Image Size

This is a NGINX template docker image that can be used as a web server, reverse proxy, load balancer and HTTP cache.

✨ Features

  • NGINX - https://nginx.org
  • NGINX template configuration
  • Web server
  • Reverse proxy
  • Load balancer
  • Rate limiting
  • HTTP cache
  • HTTP header transformations
  • HTTP/2 and HTTPS
  • Basic authentication
  • Websockets
  • Docker and docker-compose

🐀 Getting Started

1. 🚧 Prerequisites

For DEVELOPMENT:

2. πŸ“₯ Download or clone the repository

2.1. Prepare projects directory (if not exists) in your server:

# Create projects directory:
mkdir -pv ~/workspaces/projects

# Enter into projects directory:
cd ~/workspaces/projects

2.2. Follow one of the below options [A], [B] or [C]:

OPTION A. Clone the repository:

git clone https://github.com/bybatkhuu/server.nginx-template.git && \
    cd server.nginx-template

OPTION B. Clone the repository (for DEVELOPMENT: git + ssh key):

git clone git@github.com:bybatkhuu/server.nginx-template.git && \
    cd server.nginx-template

OPTION C. Download source code from releases page.

3. πŸ›  Configure the environment

[TIP] Skip this step, if you've already configured environment!

3.1. 🌎 Configure .env (environment variables) file

[IMPORTANT] Please, check environment variables section for more details.

# Copy .env.example file into .env file:
cp -v ./.env.example ./.env

# Edit environment variables to fit in your environment:
nano ./.env

3.2. 🎺 Configure compose.override.yml file

[TIP] Skip this step, if you want run with default configuration!

You can use below template compose.override.yml files for different environments:

# Copy 'compose.override.[ENV].yml' file to 'compose.override.yml' file:
cp -v ./templates/compose/compose.override.[ENV].yml ./compose.override.yml
# For example, DEVELOPMENT environment:
cp -v ./templates/compose/compose.override.dev.yml ./compose.override.yml
# For example, STAGING or PRODUCTION environment:
cp -v ./templates/compose/compose.override.prod.yml ./compose.override.yml

# Edit 'compose.override.yml' file to fit in your environment:
nano ./compose.override.yml

3.3. βœ… Check docker compose configuration is valid

[WARNING] If you get an error or warning, check your configuration files (.env or compose.override.yml).

./compose.sh validate
# Or:
docker compose config

4. πŸ”§ Configure NGINX

[TIP] Skip this step, if you've already configured NGINX.

[IMPORTANT] Please, check nginx configuration and best practices:

Use template files in templates/nginx.conf to configure NGINX:

# Copy template file into storage directory:
cp -v ./templates/nginx.conf/[TEMPLATE_BASENAME].conf.template ./volumes/storage/nginx/configs/templates/[CUSTOM_BASENAME].conf.template
# For example, Let's Encrypt HTTPS configuration for example.com domain:
cp -v ./templates/nginx.conf/100.example.com_https.lets.conf.template ./volumes/storage/nginx/configs/templates/100.example.com.conf.template

# Edit template file to fit in your nginx configuration:
nano ./volumes/storage/nginx/configs/templates/[CUSTOM_BASENAME].conf.template
# For example:
nano ./volumes/storage/nginx/configs/templates/100.example.com.conf.template

5. πŸš€ Start docker compose

[CAUTION]:

  • If ports are conflicting, you should change ports from 3. step.
  • If container names are conflicting, you should change project directory name (from server.nginx-template to something else, e.g: prod.server.nginx-template) from 2.2. step.
./compose.sh start -l
# Or:
docker compose up -d --remove-orphans --force-recreate && \
    docker compose logs -f --tail 100

6. πŸ“‘ Check service is running and monitor logs

πŸ“‹ Check service is running:

./compose.sh list
# Or:
docker compose ps

πŸ“Ÿ Monitor logs of container:

./compose.sh logs
# Or:
docker compose logs -f --tail 100

🧡 List all running processes inside container:

./compose.sh ps
# Or:
docker compose top

πŸ“Š Check resource usage of container:

./compose.sh stats
# Or:
docker compose stats

7. πŸͺ‚ Stop docker compose

./compose.sh stop
# Or:
docker compose down --remove-orphans

πŸ‘


βš™οΈ Configuration

🌎 Environment Variables

You can use the following environment variables to configure:

.env.example:

## --- NGINX configs --- ##
## NGINX basic auth username and password:
NGINX_BASIC_AUTH_USER=nginx_admin
NGINX_BASIC_AUTH_PASS="NGINX_ADMIN_PASSWORD123" # !!! CHANGE THIS TO RANDOM PASSWORD !!!


## -- Docker configs -- ##
# NGINX_HTTP_PORT=80   # port for bridge network mode
# NGINX_HTTPS_PORT=443 # port for bridge network mode

🐳 Docker container command arguments

You can use the following arguments to configure:

-s=*, --https=[self | valid | lets]
    Enable HTTPS mode:
        self  - Self-signed certificate
        valid - Valid certificate
        lets  - Let's Encrypt certificate
-b, --bash, bash, /bin/bash
    Run only bash shell.

For example as in compose.override.yml file:

    command: ["--https=self"]
    command: ["--https=valid"]
    command: ["--https=lets"]
    command: ["/bin/bash"]

πŸ“š Documentation

πŸ›€ Roadmap

  • Add more documentation.

πŸ“‘ References

About

NGINX Template: A docker image for web server, reverse proxy, load balancer, and HTTP cache with various features like rate limiting, HTTP/2, HTTPS, and more. Ideal for development and test environments.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •