/docker-nginx

Secure Nginx from scratch in a Docker container

Primary LanguageDockerfile

Nginx

Build Status Docker Pulls Docker Version Docker Size/Layers

Why not use the official container?

This is way smaller in size and opinionated for a setup behind a (Kubernetes) ingress.

Building the container locally

You could build the container locally it works like this:

docker build . --tag lansible/nginx:latest

Use as a base container

Create a server.conf to expose your website:

server {
  listen 8080 default_server;

  root /var/www/html;
  index index.html index.htm;

  location / {
    try_files $uri $uri/ =404;
  }

  # Needed otherwise redirects will get :8080 appended
  port_in_redirect off;

  # Include cache expires
  include expires.conf;

  # Enable looking for .gz files to serve directly instead of compressing at runtime
  gzip_static on;

  # Enable looking for .br files to serve directly instead of compressing at runtime
  brotli_static on;
}

Create a Dockerfile which adds this server.conf to the nginx include directory and adds your index.html or webapp.

FROM lansible/nginx:latest

# Adds above server.conf
COPY server.conf /etc/nginx/conf.d/server.conf

# Copies your index.html to the location
COPY index.html /var/www/html

Credits