Skip to content

Commit b497e0c

Browse files
authored
Merge pull request #1 from Intellection/initial
Initial
2 parents 70c0355 + 54d52fc commit b497e0c

File tree

12 files changed

+333
-1
lines changed

12 files changed

+333
-1
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
3+
!config

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 1.19.5
4+
5+
* Initial release.

Dockerfile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
FROM zappi/nginx:1.19.5 as builder
2+
3+
USER root
4+
5+
# Install build dependencies
6+
RUN apk add --no-cache \
7+
alpine-sdk \
8+
bash \
9+
findutils \
10+
gcc \
11+
gd-dev \
12+
geoip-dev \
13+
libc-dev \
14+
libedit-dev \
15+
libxslt-dev \
16+
linux-headers \
17+
make \
18+
mercurial \
19+
openssl-dev \
20+
pcre-dev \
21+
perl-dev \
22+
zlib-dev
23+
24+
WORKDIR /usr/src/
25+
26+
# Download nginx source
27+
ARG NGINX_VERSION="1.19.5"
28+
ARG NGINX_PKG="nginx-${NGINX_VERSION}.tar.gz"
29+
ARG NGINX_SHA="5c0a46afd6c452d4443f6ec0767f4d5c3e7c499e55a60cd6542b35a61eda799c"
30+
31+
RUN wget "http://nginx.org/download/${NGINX_PKG}" && \
32+
echo "${NGINX_SHA} *${NGINX_PKG}" | sha256sum -c - && \
33+
tar --no-same-owner -xzf ${NGINX_PKG} --one-top-level=nginx --strip-components=1
34+
35+
# Download headers-more module source
36+
ARG HEADERS_MORE_VERSION="0.33"
37+
ARG HEADERS_MORE_PKG="v${HEADERS_MORE_VERSION}.tar.gz"
38+
ARG HEADERS_MORE_SHA="a3dcbab117a9c103bc1ea5200fc00a7b7d2af97ff7fd525f16f8ac2632e30fbf"
39+
40+
RUN wget "https://github.com/openresty/headers-more-nginx-module/archive/${HEADERS_MORE_PKG}" && \
41+
echo "${HEADERS_MORE_SHA} *${HEADERS_MORE_PKG}" | sha256sum -c - && \
42+
tar --no-same-owner -xzf ${HEADERS_MORE_PKG} --one-top-level=headers-more --strip-components=1
43+
44+
# Compile nginx with headers-more module using original configure arguments
45+
RUN cd nginx && \
46+
CONFIGURATION_ARGUMENTS=$(nginx -V 2>&1 | sed -n -e 's/^.*arguments: //p') && \
47+
sh -c "./configure --with-compat ${CONFIGURATION_ARGUMENTS} --add-dynamic-module=/usr/src/headers-more" && \
48+
make modules
49+
50+
# Production container starts here
51+
FROM zappi/nginx:1.19.5
52+
53+
# Copy compiled module
54+
COPY --from=builder /usr/src/nginx/objs/*_module.so /etc/nginx/modules/
55+
56+
COPY ./config/ /etc/nginx/
57+
58+
STOPSIGNAL SIGQUIT
59+
EXPOSE 8080
60+
USER nginx:nginx

README.md

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,76 @@
11
# Docker Nginx Proxy
22

3-
A basic reverse proxy designed to simplify adding or modifying headers.
3+
A basic reverse proxy designed to simplify header manipulation.
4+
5+
## Usage
6+
7+
To configure the upstream, create an `app.conf` with a `server` block:
8+
9+
```nginx
10+
server {
11+
listen 8080;
12+
13+
location / {
14+
proxy_pass http://app:80;
15+
}
16+
}
17+
```
18+
19+
The file must be placed in `/etc/nginx`.
20+
21+
## Header manipulation
22+
23+
Within the `server` block you can maniplate headers using the [`headers-more`](https://github.com/openresty/headers-more-nginx-module) module:
24+
25+
```nginx
26+
server {
27+
...
28+
29+
# Remove a header
30+
more_clear_headers "Server";
31+
32+
# Set a header
33+
more_set_headers 'X-Robots-Tag: "noindex, nofollow"';
34+
35+
...
36+
}
37+
```
38+
39+
## Further customisation
40+
41+
Since you're defining a standard `server` block, you can configure it however you like over and above just header manipulation. For example, you can add a custom `location`:
42+
43+
```nginx
44+
server {
45+
...
46+
47+
# Use the default robots.txt to disallow all bots
48+
location /robots.txt {
49+
alias /etc/nginx/robots.txt;
50+
}
51+
52+
...
53+
}
54+
```
55+
56+
## Logging
57+
58+
To change how logging is configured, mount a file at `/etc/nginx/log.conf`:
59+
```nginx
60+
access_log off;
61+
error_log off;
62+
```
63+
64+
## Core configuration
65+
66+
It's also possible to modify [core configuration](http://nginx.org/en/docs/ngx_core_module.html) such as those in the `main` section by mounting a file at `/etc/nginx/main.conf`:
67+
```nginx
68+
worker_processes auto;
69+
worker_shutdown_timeout 300s;
70+
```
71+
72+
It's important to note that overriding this file will remove the current defaults hence it's always a good idea to start with a copy of the defaults.
73+
74+
## Health check
75+
76+
A health check is available on port `18080` at `/healthz`.

config/http.conf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
http {
2+
include /etc/nginx/mime.types;
3+
include /etc/nginx/log.conf;
4+
5+
server_tokens off;
6+
keepalive_timeout 20s;
7+
sendfile on;
8+
tcp_nopush on;
9+
client_max_body_size 400m;
10+
client_body_timeout 300s;
11+
12+
proxy_http_version 1.1;
13+
proxy_set_header Connection "";
14+
proxy_set_header Host $host;
15+
16+
proxy_set_header X-Real-IP $remote_addr;
17+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
18+
proxy_set_header X-Forwarded-Proto $scheme;
19+
proxy_set_header X-Forwarded-Ssl on;
20+
proxy_set_header X-Forwarded-Port $server_port;
21+
proxy_set_header X-Forwarded-Host $host;
22+
23+
proxy_read_timeout 600s;
24+
25+
include /etc/nginx/app.conf;
26+
27+
server {
28+
listen 18080 default_server;
29+
30+
location /healthz {
31+
access_log off;
32+
return 200;
33+
}
34+
}
35+
}

config/log.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
log_format main '$remote_addr - $remote_user [$time_local] $status '
2+
'"$request" $body_bytes_sent "$http_referer" '
3+
'"$http_user_agent" "$http_x_forwarded_for"';
4+
5+
access_log /dev/stdout main;
6+
error_log /dev/stdout warn;

config/main.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
worker_processes auto;
2+
worker_rlimit_nofile 8192;
3+
worker_shutdown_timeout 630s;
4+
5+
events {
6+
worker_connections 8000;
7+
}

config/mime.types

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
types {
2+
text/html html htm shtml;
3+
text/css css;
4+
text/xml xml;
5+
image/gif gif;
6+
image/jpeg jpeg jpg;
7+
application/javascript js;
8+
application/atom+xml atom;
9+
application/rss+xml rss;
10+
11+
text/mathml mml;
12+
text/plain txt;
13+
text/vnd.sun.j2me.app-descriptor jad;
14+
text/vnd.wap.wml wml;
15+
text/x-component htc;
16+
17+
image/png png;
18+
image/svg+xml svg svgz;
19+
image/tiff tif tiff;
20+
image/vnd.wap.wbmp wbmp;
21+
image/webp webp;
22+
image/x-icon ico;
23+
image/x-jng jng;
24+
image/x-ms-bmp bmp;
25+
26+
font/woff woff;
27+
font/woff2 woff2;
28+
29+
application/java-archive jar war ear;
30+
application/json json;
31+
application/mac-binhex40 hqx;
32+
application/msword doc;
33+
application/pdf pdf;
34+
application/postscript ps eps ai;
35+
application/rtf rtf;
36+
application/vnd.apple.mpegurl m3u8;
37+
application/vnd.google-earth.kml+xml kml;
38+
application/vnd.google-earth.kmz kmz;
39+
application/vnd.ms-excel xls;
40+
application/vnd.ms-fontobject eot;
41+
application/vnd.ms-powerpoint ppt;
42+
application/vnd.oasis.opendocument.graphics odg;
43+
application/vnd.oasis.opendocument.presentation odp;
44+
application/vnd.oasis.opendocument.spreadsheet ods;
45+
application/vnd.oasis.opendocument.text odt;
46+
application/vnd.openxmlformats-officedocument.presentationml.presentation
47+
pptx;
48+
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
49+
xlsx;
50+
application/vnd.openxmlformats-officedocument.wordprocessingml.document
51+
docx;
52+
application/vnd.wap.wmlc wmlc;
53+
application/x-7z-compressed 7z;
54+
application/x-cocoa cco;
55+
application/x-java-archive-diff jardiff;
56+
application/x-java-jnlp-file jnlp;
57+
application/x-makeself run;
58+
application/x-perl pl pm;
59+
application/x-pilot prc pdb;
60+
application/x-rar-compressed rar;
61+
application/x-redhat-package-manager rpm;
62+
application/x-sea sea;
63+
application/x-shockwave-flash swf;
64+
application/x-stuffit sit;
65+
application/x-tcl tcl tk;
66+
application/x-x509-ca-cert der pem crt;
67+
application/x-xpinstall xpi;
68+
application/xhtml+xml xhtml;
69+
application/xspf+xml xspf;
70+
application/zip zip;
71+
72+
application/octet-stream bin exe dll;
73+
application/octet-stream deb;
74+
application/octet-stream dmg;
75+
application/octet-stream iso img;
76+
application/octet-stream msi msp msm;
77+
78+
audio/midi mid midi kar;
79+
audio/mpeg mp3;
80+
audio/ogg ogg;
81+
audio/x-m4a m4a;
82+
audio/x-realaudio ra;
83+
84+
video/3gpp 3gpp 3gp;
85+
video/mp2t ts;
86+
video/mp4 mp4;
87+
video/mpeg mpeg mpg;
88+
video/quicktime mov;
89+
video/webm webm;
90+
video/x-flv flv;
91+
video/x-m4v m4v;
92+
video/x-mng mng;
93+
video/x-ms-asf asx asf;
94+
video/x-ms-wmv wmv;
95+
video/x-msvideo avi;
96+
}

config/nginx.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
load_module modules/ngx_http_headers_more_filter_module.so;
2+
3+
include /etc/nginx/main.conf;
4+
include /etc/nginx/http.conf;

config/robots.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
User-agent: *
2+
Disallow: /

0 commit comments

Comments
 (0)