Giter Club home page Giter Club logo

docker-nginx's Introduction

Nginx docker container

Circle CI

This is a million12/nginx docker container with Nginx web server, nicely tuned for a better performance.

Features

- HTTP/2 support
- directory structure
/data/www # meant to contain web content
/data/conf/nginx/ # extra Nginx configs to customise its settings (read more below)

The container will re-create the above structure in case it's missing (i.e. when using empty external /data volume container).

- default vhost

Default catch-all vhost is generated IF you set NGINX_GENERATE_DEFAULT_VHOST=true. It will serve the content from /data/www/default location.

- dummy SSL certificates

The default catch-all vhost is configured to work on HTTPS as well.

- internal HTTP/HTTPS proxy (if requested)

Set SET_INTERNAL_PROXY_ON_PORT and/or SET_INTERNAL_HTTPS_PROXY_ON_PORT to have internal transparent proxy on specified port. Useful when working with BrowserSync using --proxy option.

- error logging

Nginx error_log is set to stderr and therefore Nginx log is available only via docker logs [contaienr], together with supervisor logs.

This is probably best approach if you'd like to source your logs from outside the container (e.g. via docker logs or CoreOS `journald') and you don't want to worry about logging and log management inside your container.

- graceful reload after config change

Folders /etc/nginx/ and /data/conf/nginx/ are monitored for any config changes and, when they happen, Nginx is gracefully reloaded.

- Nginx status page

Nginx status page is configured under /nginx_status URL on the default vhost. Also see STATUS_PAGE_ALLOWED_IP env variable described below. Eample output:

Active connections: 1 
server accepts handled requests
11475 11475 13566 
Reading: 0 Writing: 1 Waiting: 0

Usage

docker run -d --name=web -p=80:80 -p=443:443 -e "NGINX_GENERATE_DEFAULT_VHOST=true" million12/nginx

With data container:

docker run -d --name=web-data -v /data busybox
docker run -d --name=web --volumes-from=web-data -p=80:80 -e "NGINX_GENERATE_DEFAULT_VHOST=true" million12/nginx

After that you can see the default vhost content (something like: 'default vhost # created on [timestamp]') when you open http://CONTAINER_IP:PORT/ in the browser.

Customise

Modify Nginx global configuration (http {} context) by adding configs in the following locations:

/etc/nginx/nginx.d/*.conf
/data/conf/nginx/nginx.d/*.conf

/etc/nginx/addon.d/*.conf
/data/conf/nginx/addon.d/*.conf

Add vhosts by placing their configs in following locations:

/etc/nginx/hosts.d/*.conf
/data/conf/nginx/hosts.d/*.conf

Extra configs to include inside vhost.conf, in server {} context (already included in the default vhost):

include     /etc/nginx/conf.d/default-*.conf;
include     /data/conf/nginx/conf.d/default-*.conf;

ENV variables

NGINX_GENERATE_DEFAULT_VHOST
Default: NGINX_GENERATE_DEFAULT_VHOST=false
Example: NGINX_GENERATE_DEFAULT_VHOST=true
When set to true, dummy default (catch-all) Nginx vhost config file will be generated in /etc/nginx/hosts.d/default.conf.
Use it if you need it, for example to test that your Nginx is working correctly AND/OR if you don't create default vhost config for your app but you still want some dummy catch-all vhost.

SET_INTERNAL_PROXY_ON_PORT
Default: SET_INTERNAL_PROXY_ON_PORT=null
Example: SET_INTERNAL_PROXY_ON_PORT=3000
Configure additional proxy listening on SET_INTERNAL_PROXY_ON_PORT port.
This might be useful during development, when container's ports are exposed outside under different ones. Because of different reasons you might want to access the project inside the container under the same port number as the one exposed outside. This is particularly handy for running inside the container e.g. integration tests or working with BrowserSync using --proxy option.

SET_INTERNAL_HTTPS_PROXY_ON_PORT
Default: SET_INTERNAL_HTTPS_PROXY_ON_PORT=null
Example: SET_INTERNAL_HTTPS_PROXY_ON_PORT=3000
Similar to SET_INTERNAL_PROXY_ON_PORT, but the proxy then listens with SSL support and proxies the request to HTTPS as well. Note: if you use both, SET_INTERNAL_PROXY_ON_PORT and SET_INTERNAL_HTTPS_PROXY_ON_PORT options (to have HTTP and HTTPS support), you of course need to use two different port numbers.

STATUS_PAGE_ALLOWED_IP
Default: STATUS_PAGE_ALLOWED_IP=127.0.0.1
Example: STATUS_PAGE_ALLOWED_IP=10.1.1.0/16
Configure ip address that would be allowed to see nginx status page on /nginx_status URL.
NOTE: if NGINX_GENERATE_DEFAULT_VHOST=false (which is the default setting), you'll need to add:

include     /etc/nginx/conf.d/stub-status.conf;

to your own/custom vhost file (which you surely create for your application). Add it to the server {} context, this will define the /nginx_status location.

Authors

Author: Marcin Ryzycki ([email protected])
Author: Przemyslaw Ozgo ([email protected])


Sponsored by Prototype Brewery - the new prototyping tool for building highly-interactive prototypes of your website or web app. Built on top of Neos CMS and Zurb Foundation framework.

docker-nginx's People

Contributors

pozgo avatar ryzy avatar

Watchers

 avatar  avatar  avatar

Forkers

soluno

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.