From e5ecd977eaef8ace7ea8f56864842d223a794abc Mon Sep 17 00:00:00 2001
From: Benjamin Bertrand <benjamin.bertrand@esss.se>
Date: Sun, 28 Apr 2019 13:41:52 +0200
Subject: [PATCH] Add nginx dockerfile and configuration

---
 .dockerignore |  3 +++
 Dockerfile    | 11 +++++++++++
 default.conf  | 39 +++++++++++++++++++++++++++++++++++++++
 nginx.conf    | 42 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 95 insertions(+)
 create mode 100644 .dockerignore
 create mode 100644 Dockerfile
 create mode 100644 default.conf
 create mode 100644 nginx.conf

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..96b11ac
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,3 @@
+.gitlab-ci.yml
+README.md
+PythonServer
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..c60b90a
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,11 @@
+FROM nginx:1.16
+
+# Change directories owwnership to start nginx as non root
+RUN chown -R nginx /var/cache/nginx /var/log/nginx;
+
+COPY nginx.conf /etc/nginx/
+COPY default.conf /etc/nginx/conf.d/
+
+COPY ./WebSites /usr/share/nginx/web/
+
+USER nginx
diff --git a/default.conf b/default.conf
new file mode 100644
index 0000000..9d1772d
--- /dev/null
+++ b/default.conf
@@ -0,0 +1,39 @@
+server {
+    listen 8000 default_server;
+
+    location / {
+        root   /usr/share/nginx/web/pos;
+    }
+
+    location ~ ^/(pvs|interlocks|instruments) {
+        root   /usr/share/nginx/web;
+    }
+
+    location /dev {
+        alias   /usr/share/nginx/web/pos-dev;
+    }
+
+    # static json and png data files
+    location ~ ^/data/.*\.(png|json)$ {
+        root   /usr/share/nginx;
+    }
+
+    location /data {
+        rewrite /data/(.*)$ /$1 break;
+        proxy_pass http://pos_python_server:8080;
+    }
+
+    location /plot {
+        rewrite /plot/(.*)$ /$1 break;
+        proxy_pass http://archiver-01.tn.esss.lu.se:17668/;
+    }
+
+    #error_page  404              /404.html;
+
+    # redirect server error pages to the static page /50x.html
+    error_page   500 502 503 504  /50x.html;
+    location = /50x.html {
+        root   /usr/share/nginx/html;
+    }
+
+}
diff --git a/nginx.conf b/nginx.conf
new file mode 100644
index 0000000..b4111a5
--- /dev/null
+++ b/nginx.conf
@@ -0,0 +1,42 @@
+worker_processes  1;
+
+error_log  /var/log/nginx/error.log warn;
+pid        /var/cache/nginx/nginx.pid;
+
+
+events {
+    worker_connections  1024;
+}
+
+
+http {
+    include       /etc/nginx/mime.types;
+    default_type  application/octet-stream;
+
+    log_format graylog2_json escape=json '{ "timestamp": "$time_iso8601", '
+                 '"remote_addr": "$remote_addr", '
+                 '"body_bytes_sent": $body_bytes_sent, '
+                 '"request_time": $request_time, '
+                 '"response_status": $status, '
+                 '"request": "$request", '
+                 '"request_method": "$request_method", '
+                 '"host": "$host",'
+                 '"upstream_cache_status": "$upstream_cache_status",'
+                 '"upstream_addr": "$upstream_addr",'
+                 '"http_x_forwarded_for": "$http_x_forwarded_for",'
+                 '"http_referrer": "$http_referer", '
+                 '"http_user_agent": "$http_user_agent", '
+                 '"http_version": "$server_protocol", '
+                 '"nginx_access": true }';
+
+    access_log /var/log/nginx/access.log graylog2_json;
+
+    sendfile        on;
+    #tcp_nopush     on;
+
+    keepalive_timeout  65;
+
+    #gzip  on;
+
+    include /etc/nginx/conf.d/*.conf;
+}
-- 
GitLab