From 9b2bc985e0608e59660dc797dff414c0735c658f Mon Sep 17 00:00:00 2001 From: butomo1989 Date: Thu, 2 Jul 2020 14:16:02 +0200 Subject: [PATCH] Added sample config of nginx --- README_CUSTOM_CONFIG.md | 2 +- nginx/README.md | 15 ++++++++++ nginx/conf.d/data/data.json | 11 ++++++++ nginx/conf.d/default.conf | 43 ++++++++++++++++++++++++++++ nginx/conf.d/index.html | 13 +++++++++ nginx/conf.d/scripts/main.js | 55 ++++++++++++++++++++++++++++++++++++ nginx/conf.d/styles/main.css | 13 +++++++++ nginx/default | 21 -------------- 8 files changed, 151 insertions(+), 22 deletions(-) create mode 100644 nginx/README.md create mode 100644 nginx/conf.d/data/data.json create mode 100755 nginx/conf.d/default.conf create mode 100644 nginx/conf.d/index.html create mode 100644 nginx/conf.d/scripts/main.js create mode 100644 nginx/conf.d/styles/main.css delete mode 100755 nginx/default diff --git a/README_CUSTOM_CONFIG.md b/README_CUSTOM_CONFIG.md index 3000c4f..c3b0649 100644 --- a/README_CUSTOM_CONFIG.md +++ b/README_CUSTOM_CONFIG.md @@ -81,4 +81,4 @@ For the first run, this will create a new avd and all the changes will be access Nginx ----- -You can have 1 nginx service to handle multiple containers. Sample nginx configuration is [this](nginx/default) and sample call is ```http://127.0.0.1/container-1/?nginx=&path=/container-1/websockify&view_only=true&password=secr3t``` +Sample nginx configuration can be found [here](nginx/README.md) and sample call is ```http://127.0.0.1/container-1/?nginx=&path=/container-1/websockify&view_only=true&password=secr3t``` diff --git a/nginx/README.md b/nginx/README.md new file mode 100644 index 0000000..5e85db0 --- /dev/null +++ b/nginx/README.md @@ -0,0 +1,15 @@ +Nginx +----- + +You can have one page which contains the list of running container. + +##### Quick Start + +1. Run 2 docker-android container which have port 6081 and 6082 + +2. Run docker nginx + ``` + docker run -d --name nginx --network host -v $PWD/conf.d:/etc/nginx/conf.d nginx:1.18.0 + ``` + +3. Access [http://127.0.0.1](http://127.0.0.1) from Web-Browser to see the list of running containers OR open '''http://127.0.0.1/container-1/?nginx=&path=/container-1/websockify&view_only=true&password=secr3t''' to see specific container. diff --git a/nginx/conf.d/data/data.json b/nginx/conf.d/data/data.json new file mode 100644 index 0000000..4bc1339 --- /dev/null +++ b/nginx/conf.d/data/data.json @@ -0,0 +1,11 @@ +containers = '[\ + {\ + "No": "1", \ + "Name": "Emulator 01", \ + "VNC": "http://127.0.0.1/container-1/?nginx=&path=/container-1/websockify&view_only=true"\ + }, \ + {\ + "No": "2", \ + "Name": "Emulator 02", \ + "VNC": "http://127.0.0.1/container-2/?nginx=&path=/container-2/websockify&view_only=true"\ +}]'; diff --git a/nginx/conf.d/default.conf b/nginx/conf.d/default.conf new file mode 100755 index 0000000..a1b527e --- /dev/null +++ b/nginx/conf.d/default.conf @@ -0,0 +1,43 @@ +server { + listen 80; + server_name _; + + location / { + root /etc/nginx/conf.d; + index index.html; + } + + location /container-1/ { + proxy_pass http://127.0.0.1:6081/; + } + + location /container-1/websockify { + proxy_pass http://127.0.0.1:6081/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # VNC connection timeout + proxy_read_timeout 61s; + + # Disable cache + proxy_buffering off; + } + + location /container-2/ { + proxy_pass http://127.0.0.1:6082/; + } + + location /container-2/websockify { + proxy_pass http://127.0.0.1:6082/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + # VNC connection timeout + proxy_read_timeout 61s; + + # Disable cache + proxy_buffering off; + } +} diff --git a/nginx/conf.d/index.html b/nginx/conf.d/index.html new file mode 100644 index 0000000..fc69a72 --- /dev/null +++ b/nginx/conf.d/index.html @@ -0,0 +1,13 @@ + + + + + List of docker-android containers + + + +
+ + + + diff --git a/nginx/conf.d/scripts/main.js b/nginx/conf.d/scripts/main.js new file mode 100644 index 0000000..016b0f6 --- /dev/null +++ b/nginx/conf.d/scripts/main.js @@ -0,0 +1,55 @@ +var devices = JSON.parse(containers); + +var headers = []; +for (var pos = 0; pos < devices.length; pos++) { + for (var deviceKey in devices[pos]) { + // Check if key is already added to headers + if (headers.indexOf(deviceKey) === -1) { + headers.push(deviceKey); + } + } +} + +// Create a table +var table = document.createElement("table"); + +// Insert table header +var tr = table.insertRow(-1); +for (var pos = 0; pos < headers.length; pos++) { + var th = document.createElement("th"); // TABLE HEADER. + var header = headers[pos]; + th.innerHTML = header; + tr.appendChild(th); +} + +// Insert table content +for (var pos = 0; pos < devices.length; pos++) { + tr = table.insertRow(-1); + for (var index = 0; index < headers.length; index++) { + var td = document.createElement("td"); + var content = devices[pos][headers[index]]; + + if (index == 1) { + var link = document.createElement("a"); + link.href = devices[pos][headers[index+1]]; + link.innerHTML = content; + td.appendChild(link); + } else if (index === 2) { + var object = document.createElement("object"); + object.type = "text/html" + object.data = content; + object.width = "950px"; + object.height = "950px"; + td.appendChild(object); + } else { + td.innerHTML = content; + } + + tr.appendChild(td); + } +} + +// Put the table inside div +var divContainer = document.getElementById("showData"); +divContainer.innerHTML = ""; +divContainer.appendChild(table); diff --git a/nginx/conf.d/styles/main.css b/nginx/conf.d/styles/main.css new file mode 100644 index 0000000..ca78089 --- /dev/null +++ b/nginx/conf.d/styles/main.css @@ -0,0 +1,13 @@ +th, td { + font:14px Verdana; +} +table, th, td +{ + border: solid 1px #DDD; + border-collapse: collapse; + padding: 2px 3px; + text-align: center; +} +th { + font-weight:bold; +} diff --git a/nginx/default b/nginx/default deleted file mode 100755 index 0b5deef..0000000 --- a/nginx/default +++ /dev/null @@ -1,21 +0,0 @@ -server { - listen 80; - server_name _; - - location /container-1/ { - proxy_pass http://127.0.0.1:6080/; - } - - location /container-1/websockify { - proxy_pass http://127.0.0.1:6080/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - - # VNC connection timeout - proxy_read_timeout 61s; - - # Disable cache - proxy_buffering off; - } -}