-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f5c6d06
Showing
6 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
FROM ubuntu:trusty | ||
MAINTAINER Abe Voelker <[email protected]> | ||
|
||
# Provide a custom nginx.conf, tweaked for Docker use | ||
COPY nginx.conf /data/conf/ | ||
|
||
# Ensure UTF-8 locale | ||
COPY locale /etc/default/locale | ||
RUN locale-gen en_US.UTF-8 &&\ | ||
DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales &&\ | ||
# Install build dependencies | ||
apt-get update &&\ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common &&\ | ||
# Add official nginx APT repositories | ||
apt-add-repository ppa:nginx/stable &&\ | ||
# Update apt cache with PPAs | ||
apt-get update &&\ | ||
# Install nginx | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y nginx &&\ | ||
# Copy default config files to /data | ||
/bin/bash -c "cp -a /etc/nginx/{conf.d,sites-enabled} /data/" | ||
|
||
VOLUME ["/data", "/var/www", "/var/cache/nginx", "/var/log/nginx"] | ||
|
||
CMD ["nginx", "-c", "/data/conf/nginx.conf"] | ||
|
||
EXPOSE 80 443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Abe Voelker | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
PROJECT ?= abevoelker/nginx | ||
|
||
ifdef REGISTRY | ||
IMAGE=$(REGISTRY)/$(PROJECT) | ||
else | ||
IMAGE=$(PROJECT) | ||
endif | ||
|
||
all: | ||
@echo "Available targets:" | ||
@echo " * build - build a Docker image for $(IMAGE)" | ||
@echo " * pull - pull down previous docker builds of $(IMAGE)" | ||
|
||
build: Dockerfile | ||
docker build -t $(IMAGE) . | ||
|
||
pull: | ||
docker pull $(IMAGE) || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# nginx Dockerfile | ||
|
||
Docker image for nginx. I created this image because the [official nginx Docker image][official-image] is kind of weak in my opinion, mainly in terms of it only using the development version of nginx and not making configuration easy. | ||
|
||
The following tweaks have been applied to Dockerize nginx: | ||
|
||
* Builds from the official nginx *stable* PPA (the official Docker nginx image uses the non-stable, development/mainline version of nginx!). | ||
* Disable daemonization and log to stdout and stderr directly (standard Dockerization). | ||
* Set `worker_processes` to `auto`. This is the number of cores that nginx will use. The Ubuntu installer will detect the amount of cores the machine has and encode that in nginx.conf by default, so by default this would be set to the number of cores of the machine that builds the Docker image (not what you want). | ||
* Bypass copy-on-write filesystem for `/data`, `/var/www`, `/var/cache/nginx`, and `/var/log/nginx` directories. This results in better performance from the locations that nginx needs to modify the disk. | ||
* Change default config to read configuration from `/data` directories (see configuration section for more info). | ||
|
||
## Basic usage | ||
|
||
``` | ||
$ docker run -d -p 8080:80 abevoelker/nginx | ||
a05187a086b896afed4d8f53fe523de3933682d2997d3bdf105f3678f53a3648 | ||
$ curl -I http://localhost:8080 | ||
HTTP/1.1 200 OK | ||
Server: nginx/1.6.2 | ||
Date: Sun, 09 Nov 2014 00:39:09 GMT | ||
Content-Type: text/html | ||
Content-Length: 867 | ||
Last-Modified: Sun, 09 Nov 2014 00:33:54 GMT | ||
Connection: keep-alive | ||
ETag: "545eb672-363" | ||
Accept-Ranges: bytes | ||
``` | ||
|
||
## Configuration | ||
|
||
### sites-enabled | ||
|
||
Site configuration files go in `/data/sites-enabled/`: | ||
|
||
``` | ||
$ ls /tmp/sites-enabled | ||
example.com | ||
$ docker run -v /tmp/sites-enabled:/data/sites-enabled abevoelker/nginx | ||
``` | ||
|
||
### nginx.conf | ||
|
||
If you have a custom `nginx.conf`, just mount it to `/data/conf/`: | ||
|
||
``` | ||
$ ls /tmp/conf | ||
nginx.conf | ||
$ docker run -v /tmp/conf:/data/conf abevoelker/nginx | ||
``` | ||
|
||
If for some reason you don't want to call it nginx.conf or want to put it somewhere else, you'll need to change the default run command to reference it: | ||
|
||
``` | ||
$ docker run -v /tmp/foo:/foo abevoelker/nginx nginx -c /foo/nginx.conf | ||
``` | ||
|
||
Be sure to check out the `nginx.conf` provided with this image for Docker-specific tweaks. | ||
|
||
### conf.d | ||
|
||
Extra `.conf` files go in `/data/conf.d/`: | ||
|
||
``` | ||
$ docker run -v /tmp/conf.d:/data/conf.d abevoelker/nginx | ||
``` | ||
|
||
Note that the default base `nginx.conf` is configured to only include files in this directory with the suffix `.conf`. | ||
|
||
## Building | ||
|
||
There's a Makefile with `make build` included as a shorthand for building the image. If you're using a private registry, you can do `REGISTRY=example.com make build` and the image will be tagged `example.com/abevoelker/nginx`. | ||
|
||
There's also a `make pull` included as a shorthand for pulling the image. | ||
|
||
## License | ||
|
||
MIT license. | ||
|
||
[official-image]: https://github.com/nginxinc/docker-nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
LANGUAGE="en_US.UTF-8" | ||
LANG="en_US.UTF-8" | ||
LC_ALL="en_US.UTF-8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
user www-data; | ||
worker_processes auto; | ||
pid /run/nginx.pid; | ||
daemon off; | ||
|
||
events { | ||
worker_connections 768; | ||
# multi_accept on; | ||
} | ||
|
||
http { | ||
|
||
## | ||
# Basic Settings | ||
## | ||
|
||
sendfile on; | ||
tcp_nopush on; | ||
tcp_nodelay on; | ||
keepalive_timeout 65; | ||
types_hash_max_size 2048; | ||
# server_tokens off; | ||
|
||
# server_names_hash_bucket_size 64; | ||
# server_name_in_redirect off; | ||
|
||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
## | ||
# Logging Settings | ||
## | ||
|
||
access_log /dev/stdout; | ||
error_log /dev/stderr; | ||
|
||
## | ||
# Gzip Settings | ||
## | ||
|
||
gzip on; | ||
gzip_disable "msie6"; | ||
|
||
# gzip_vary on; | ||
# gzip_proxied any; | ||
# gzip_comp_level 6; | ||
# gzip_buffers 16 8k; | ||
# gzip_http_version 1.1; | ||
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; | ||
|
||
## | ||
# nginx-naxsi config | ||
## | ||
# Uncomment it if you installed nginx-naxsi | ||
## | ||
|
||
#include /etc/nginx/naxsi_core.rules; | ||
|
||
## | ||
# nginx-passenger config | ||
## | ||
# Uncomment it if you installed nginx-passenger | ||
## | ||
|
||
#passenger_root /usr; | ||
#passenger_ruby /usr/bin/ruby; | ||
|
||
## | ||
# Virtual Host Configs | ||
## | ||
|
||
include /data/conf.d/*.conf; | ||
include /data/sites-enabled/*; | ||
} | ||
|
||
|
||
#mail { | ||
# # See sample authentication script at: | ||
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript | ||
# | ||
# # auth_http localhost/auth.php; | ||
# # pop3_capabilities "TOP" "USER"; | ||
# # imap_capabilities "IMAP4rev1" "UIDPLUS"; | ||
# | ||
# server { | ||
# listen localhost:110; | ||
# protocol pop3; | ||
# proxy on; | ||
# } | ||
# | ||
# server { | ||
# listen localhost:143; | ||
# protocol imap; | ||
# proxy on; | ||
# } | ||
#} |