From 593cc41489966d6e868c9c3ce567f96cb3d92799 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Tue, 13 Sep 2016 23:31:48 +0100 Subject: [PATCH 01/12] Initial additions for reverse proxy --- Readme.md | 6 ++-- docker-compose.yml | 21 ++++------- nginx.cfg | 86 ++++++++++++++++++++++++++++++++++++++++++++++ start.sh | 4 ++- 4 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 nginx.cfg diff --git a/Readme.md b/Readme.md index 2442c5e..88fd9a8 100644 --- a/Readme.md +++ b/Readme.md @@ -1,9 +1,11 @@ # Media Server in a box -A script and accompanying docker-compose file to go from a bare Docker install to a ready to be configured media server in seconds. Write up to follow. +A script and accompanying docker-compose file to go from a bare Docker install to a ready to be configured media server in seconds. Write up to follow. + +**This Version uses a reverse proxy and requires DNS configuration** ## One liner to get started: *Note: This needs to be run as root* -``` curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/master/start.sh | bash ``` +``` curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/start.sh | bash ``` diff --git a/docker-compose.yml b/docker-compose.yml index bf688a9..c68985b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,8 +14,6 @@ services: - data - container:media restart: always - ports: - - "6789:6789" deluge: image: adamant/deluge @@ -25,11 +23,6 @@ services: - data - container:media restart: always - ports: - - "8112:8112" - - "58846:58846" - - "53160:53160" - - "53160:53160/udp" sickrage: image: adamant/sickrage @@ -40,8 +33,6 @@ services: - data - container:media restart: always - ports: - - "8081:8081" couchpotato: image: adamant/couchpotato @@ -52,8 +43,6 @@ services: - data - container:media restart: always - ports: - - "5050:5050" headphones: image: adamant/headphones @@ -64,8 +53,6 @@ services: - data - container:media restart: always - ports: - - "8181:8181" plex: image: adamant/alpine-plex @@ -88,5 +75,11 @@ services: volumes_from: - data restart: always + + web: + image: nginx:alpine + volumes: + - $VOLDIR/launcher/nginx.cfg:/etc/nginx/conf.d/media.cfg + restart: always ports: - - "8182:8181" + - "80:80" diff --git a/nginx.cfg b/nginx.cfg new file mode 100644 index 0000000..046eca0 --- /dev/null +++ b/nginx.cfg @@ -0,0 +1,86 @@ +resolver 127.0.0.1; +server { + listen 80; + server_name genie; + + location / { + set $test ""; + + # If a request to / comes in, 301 redirect to the main plex page, + # but only if it doesn't contain the X-Plex-Device-Name header or query argument. + # This fixes a bug where you get permission issues when accessing the web dashboard. + if ($http_x_plex_device_name = '') { + set $test A; + } + if ($arg_X-Plex-Device-Name = '') { + set $test "${test}B"; + } + if ($test = AB) { + rewrite ^/$ https://$http_host/web/index.html; + } + + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_pass https://genie:32400; + + # Plex proxy settings. + proxy_redirect off; + proxy_buffering off; + + ## Required for Websockets + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_read_timeout 36000s; ## Timeout after 10 hours + } +} +server { + listen 80; + server_name deluge.genie; + + location / { + proxy_pass http://deluge:8112; + } +} +server { + listen 80; + server_name sickrage.genie; + + location / { + proxy_pass https://sickrage:8081; + } +} +server { + listen 80; + server_name nzbget.genie; + + location / { + proxy_pass https://nzbget:6791; + } +} +server { + listen 80; + server_name plexpy.genie; + + location / { + proxy_pass http://plexpy:8181; + } +} +server { + listen 80; + server_name couchpotato.genie; + + location / { + proxy_pass http://couchpotato:5050; + } +} +server { + listen 80; + server_name headphones.genie; + + location / { + proxy_pass http://headphones:8181; + } +} diff --git a/start.sh b/start.sh index 846d8ed..4f02c62 100644 --- a/start.sh +++ b/start.sh @@ -28,6 +28,8 @@ for ((i=0; i<$slen; i++)); do [[ $( ls -dn $VOLDIR/${SERVICES[$i]} | awk '{print $3}') != ${SERVICEUID[$i]} ]] && echo "Chowning $VOLDIR/${SERVICES[$i]} to user ${SERVICEUID[$i]}" && chown ${SERVICEUID[$i]}:${SERVICEUID[$i]} $VOLDIR/${SERVICES[$i]} done -[[ ! -a $VOLDIR/launcher/docker-compose.yml ]] && echo "Downloading docker-compose.yml.." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/master/docker-compose.yml > $VOLDIR/launcher/media-compose.yml +[[ ! -a $VOLDIR/launcher/docker-compose.yml ]] && echo "Downloading docker-compose.yml.." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/docker-compose.yml > $VOLDIR/launcher/media-compose.yml +[[ ! -a $VOLDIR/launcher/nginx.cfg ]] && echo "Downloading nginx.cfg..." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/nginx.cfg > $VOLDIR/launcher/nginx.cfg + echo "Starting services..." exec docker-compose -p media -f $VOLDIR/launcher/media-compose.yml up -d From 40c2538b1b5e696fa1dade22c11643f8f79b16c4 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Tue, 13 Sep 2016 23:56:44 +0100 Subject: [PATCH 02/12] Fix nginx file names bug --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index c68985b..e06c69c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -79,7 +79,7 @@ services: web: image: nginx:alpine volumes: - - $VOLDIR/launcher/nginx.cfg:/etc/nginx/conf.d/media.cfg + - $VOLDIR/launcher/nginx.cfg:/etc/nginx/conf.d/media.conf restart: always ports: - "80:80" From 202800d30cbecb01be2097194f3d24499c3ff8e9 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Wed, 14 Sep 2016 00:05:41 +0100 Subject: [PATCH 03/12] Path fixes for media-compose.yml --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index 4f02c62..3bd00cc 100644 --- a/start.sh +++ b/start.sh @@ -28,7 +28,7 @@ for ((i=0; i<$slen; i++)); do [[ $( ls -dn $VOLDIR/${SERVICES[$i]} | awk '{print $3}') != ${SERVICEUID[$i]} ]] && echo "Chowning $VOLDIR/${SERVICES[$i]} to user ${SERVICEUID[$i]}" && chown ${SERVICEUID[$i]}:${SERVICEUID[$i]} $VOLDIR/${SERVICES[$i]} done -[[ ! -a $VOLDIR/launcher/docker-compose.yml ]] && echo "Downloading docker-compose.yml.." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/docker-compose.yml > $VOLDIR/launcher/media-compose.yml +[[ ! -a $VOLDIR/launcher/media-compose.yml ]] && echo "Downloading media-compose.yml.." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/docker-compose.yml > $VOLDIR/launcher/media-compose.yml [[ ! -a $VOLDIR/launcher/nginx.cfg ]] && echo "Downloading nginx.cfg..." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/nginx.cfg > $VOLDIR/launcher/nginx.cfg echo "Starting services..." From 808da5f78c1e8abb1eaef35fa83470a0584edac5 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Wed, 14 Sep 2016 00:11:28 +0100 Subject: [PATCH 04/12] Remove plex container from net: host --- docker-compose.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index e06c69c..31d5be5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -64,9 +64,16 @@ services: - data - container:media restart: always - network_mode: "host" ports: + - "1900:1900/udp" + - "3005:3005" + - "5353:5353/udp" + - "8324:8324" - "32400:32400" + - "32410:32410/udp" + - "32412-32414:32412-32414/udp" + - "32469:32469" + plexpy: image: adamant/plexpy From 693ea4553509ffff4b15b25c56672b914391c3b7 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Wed, 14 Sep 2016 00:21:08 +0100 Subject: [PATCH 05/12] Nginx path fixes --- nginx.cfg | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nginx.cfg b/nginx.cfg index 046eca0..2e38870 100644 --- a/nginx.cfg +++ b/nginx.cfg @@ -1,7 +1,7 @@ resolver 127.0.0.1; server { listen 80; - server_name genie; + server_name plex.genie; location / { set $test ""; @@ -16,14 +16,14 @@ server { set $test "${test}B"; } if ($test = AB) { - rewrite ^/$ https://$http_host/web/index.html; + rewrite ^/$ http://$http_host/web/index.html; } proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass https://genie:32400; + proxy_pass http://plex:32400; # Plex proxy settings. proxy_redirect off; @@ -49,7 +49,7 @@ server { server_name sickrage.genie; location / { - proxy_pass https://sickrage:8081; + proxy_pass http://sickrage:8081; } } server { @@ -57,7 +57,7 @@ server { server_name nzbget.genie; location / { - proxy_pass https://nzbget:6791; + proxy_pass http://nzbget:6791; } } server { From 1825bc66640a59e5598c92ba58975e89cdf30279 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Wed, 14 Sep 2016 15:12:26 +0100 Subject: [PATCH 06/12] Added plex host whitelisting, fix for no net=host --- start.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/start.sh b/start.sh index 3bd00cc..ed24acc 100644 --- a/start.sh +++ b/start.sh @@ -28,6 +28,10 @@ for ((i=0; i<$slen; i++)); do [[ $( ls -dn $VOLDIR/${SERVICES[$i]} | awk '{print $3}') != ${SERVICEUID[$i]} ]] && echo "Chowning $VOLDIR/${SERVICES[$i]} to user ${SERVICEUID[$i]}" && chown ${SERVICEUID[$i]}:${SERVICEUID[$i]} $VOLDIR/${SERVICES[$i]} done +#Since we are not using net=host, we need to whitelist the subnet in plex. ##TODO## Make this overrideable with commandline argument +[[ ! -a $VOLDIR/plex/Plex\ Media\ Server/Preferences.xml ]] && echo Adding subnet to Plex Whitelist... && mkdir -p $VOLDIR/plex/Plex\ Media\ Server/ && \ + echo -e "\n" > $VOLDIR/plex/Plex\ Media\ Server/Preferences.xml && chown -R 787:787 $VOLDIR/plex + [[ ! -a $VOLDIR/launcher/media-compose.yml ]] && echo "Downloading media-compose.yml.." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/docker-compose.yml > $VOLDIR/launcher/media-compose.yml [[ ! -a $VOLDIR/launcher/nginx.cfg ]] && echo "Downloading nginx.cfg..." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/nginx.cfg > $VOLDIR/launcher/nginx.cfg From ad0750ca35c9e156ba62a98567e239c2f106da2a Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Wed, 14 Sep 2016 15:34:27 +0100 Subject: [PATCH 07/12] Recursively chown config directories --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index ed24acc..7924dbf 100644 --- a/start.sh +++ b/start.sh @@ -25,7 +25,7 @@ docker-compose version &> /dev/null slen=${#SERVICES[@]} for ((i=0; i<$slen; i++)); do [[ ! -d $VOLDIR/${SERVICES[$i]} ]] && echo "Creating folder $VOLDIR/${SERVICES[$i]}" && mkdir -p $VOLDIR/${SERVICES[$i]} - [[ $( ls -dn $VOLDIR/${SERVICES[$i]} | awk '{print $3}') != ${SERVICEUID[$i]} ]] && echo "Chowning $VOLDIR/${SERVICES[$i]} to user ${SERVICEUID[$i]}" && chown ${SERVICEUID[$i]}:${SERVICEUID[$i]} $VOLDIR/${SERVICES[$i]} + [[ $( ls -dn $VOLDIR/${SERVICES[$i]} | awk '{print $3}') != ${SERVICEUID[$i]} ]] && echo "Chowning $VOLDIR/${SERVICES[$i]} to user ${SERVICEUID[$i]}" && chown -R ${SERVICEUID[$i]}:${SERVICEUID[$i]} $VOLDIR/${SERVICES[$i]} done #Since we are not using net=host, we need to whitelist the subnet in plex. ##TODO## Make this overrideable with commandline argument From f6f34734eb9075bd08dbd083cd6f06dcf9895f2f Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Wed, 8 Feb 2017 23:46:50 +0000 Subject: [PATCH 08/12] Add support for Radarr --- docker-compose.yml | 10 ++++++++++ nginx.cfg | 8 ++++++++ start.sh | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 31d5be5..574a85d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,6 +54,16 @@ services: - container:media restart: always + radarr: + image: adamant/radarr + depends_on: + - deluge + - nzbget + volumes_from: + - data + - container:media + restart: always + plex: image: adamant/alpine-plex depends_on: diff --git a/nginx.cfg b/nginx.cfg index 2e38870..643b225 100644 --- a/nginx.cfg +++ b/nginx.cfg @@ -84,3 +84,11 @@ server { proxy_pass http://headphones:8181; } } +server { + listen 80; + server_name radarr.genie; + + location / { + proxy_pass http://radarr:7878; + } +} diff --git a/start.sh b/start.sh index 7924dbf..6bd66b0 100644 --- a/start.sh +++ b/start.sh @@ -4,8 +4,8 @@ # Prereqs: docker, docker-compose, curl (https) export VOLDIR="/volumes/media-server" -SERVICES=("couchpotato" "deluge" "headphones" "nzbget" "plex" "plexpy" "sickrage" "launcher") -SERVICEUID=("745" "647" "526" "236" "787" "426" "439" "0") +SERVICES=("couchpotato" "deluge" "headphones" "nzbget" "plex" "plexpy" "sickrage" "launcher" "radarr") +SERVICEUID=("745" "647" "526" "236" "787" "426" "439" "0" "368") [[ $EUID -ne 0 ]] && echo "Please run this script as root" && exit 1 From a339e3d2613f0d9b875aebcf95c1375f58bad447 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Thu, 9 Feb 2017 00:20:06 +0000 Subject: [PATCH 09/12] Fix docker-compose spacing --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 574a85d..05d6b4f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -62,7 +62,7 @@ services: volumes_from: - data - container:media - restart: always + restart: always plex: image: adamant/alpine-plex From f7935930f56f972818625dd4e08323f1dd9dac0f Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Wed, 1 Mar 2017 18:07:40 +0000 Subject: [PATCH 10/12] Remove unused services --- docker-compose.yml | 20 -------------------- start.sh | 4 ++-- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 05d6b4f..3f08c95 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,26 +44,6 @@ services: - container:media restart: always - headphones: - image: adamant/headphones - depends_on: - - deluge - - nzbget - volumes_from: - - data - - container:media - restart: always - - radarr: - image: adamant/radarr - depends_on: - - deluge - - nzbget - volumes_from: - - data - - container:media - restart: always - plex: image: adamant/alpine-plex depends_on: diff --git a/start.sh b/start.sh index 6bd66b0..d36c57d 100644 --- a/start.sh +++ b/start.sh @@ -4,8 +4,8 @@ # Prereqs: docker, docker-compose, curl (https) export VOLDIR="/volumes/media-server" -SERVICES=("couchpotato" "deluge" "headphones" "nzbget" "plex" "plexpy" "sickrage" "launcher" "radarr") -SERVICEUID=("745" "647" "526" "236" "787" "426" "439" "0" "368") +SERVICES=("couchpotato" "deluge" "nzbget" "plex" "plexpy" "sickrage" "launcher") +SERVICEUID=("745" "647" "236" "787" "426" "439" "0") [[ $EUID -ne 0 ]] && echo "Please run this script as root" && exit 1 From a9eb32c6dbce7308597598af99ec50d8a5e81e7a Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Wed, 1 Mar 2017 18:29:10 +0000 Subject: [PATCH 11/12] Make start.sh a config check rather than a run command --- start.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/start.sh b/start.sh index d36c57d..afdda94 100644 --- a/start.sh +++ b/start.sh @@ -16,11 +16,10 @@ docker version &> /dev/null docker-compose version &> /dev/null [[ $? -ne 0 ]] && echo "docker-compose not found. Please check your configuration." && exit 1 # Check if media container is configured -[[ $(docker ps -a --filter="name=media" | wc -l) != "2" ]] && echo "Cannot find a media container - please configure one with your media mounted at /media inside the container before running this script (to keep the size down use tianon/true)" && exit 1 +[[ $(docker ps -a --filter="name=media" | wc -l) != "2" ]] && echo "Cannot find a media container - please configure one with your media mounted at /media inside the container. to keep the size down use tianon/true)" && exit 1 # Check if volumes folder exists [[ ! -d $VOLDIR ]] && echo "Creating volumes folder..." && mkdir -p $VOLDIR -[[ ! -d $VOLDIR/couchpotato ]] slen=${#SERVICES[@]} for ((i=0; i<$slen; i++)); do @@ -32,8 +31,11 @@ done [[ ! -a $VOLDIR/plex/Plex\ Media\ Server/Preferences.xml ]] && echo Adding subnet to Plex Whitelist... && mkdir -p $VOLDIR/plex/Plex\ Media\ Server/ && \ echo -e "\n" > $VOLDIR/plex/Plex\ Media\ Server/Preferences.xml && chown -R 787:787 $VOLDIR/plex -[[ ! -a $VOLDIR/launcher/media-compose.yml ]] && echo "Downloading media-compose.yml.." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/docker-compose.yml > $VOLDIR/launcher/media-compose.yml +[[ ! -a ./docker-compose.yml ]] && echo "Downloading Docker Compose config.." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/docker-compose.yml > ./docker-compose.yml [[ ! -a $VOLDIR/launcher/nginx.cfg ]] && echo "Downloading nginx.cfg..." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/proxy/nginx.cfg > $VOLDIR/launcher/nginx.cfg -echo "Starting services..." -exec docker-compose -p media -f $VOLDIR/launcher/media-compose.yml up -d +echo "#####################################" +echo "# Config and directory struture OK! #" +echo "#####################################" +echo +echo "Run docker-compose up -d to start the containers..." From 9dcbb74fa1026197f1ec9c936aa5a648fac925f2 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Wed, 1 Mar 2017 18:33:47 +0000 Subject: [PATCH 12/12] Finish Merge --- start.sh | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/start.sh b/start.sh index 70ee07e..afdda94 100644 --- a/start.sh +++ b/start.sh @@ -4,13 +4,8 @@ # Prereqs: docker, docker-compose, curl (https) export VOLDIR="/volumes/media-server" -<<<<<<< HEAD SERVICES=("couchpotato" "deluge" "nzbget" "plex" "plexpy" "sickrage" "launcher") SERVICEUID=("745" "647" "236" "787" "426" "439" "0") -======= -SERVICES=("couchpotato" "deluge" "headphones" "nzbget" "plex" "plexpy" "sickrage" "launcher" "radarr") -SERVICEUID=("745" "647" "526" "236" "787" "426" "439" "0" "326") ->>>>>>> master [[ $EUID -ne 0 ]] && echo "Please run this script as root" && exit 1 @@ -32,7 +27,6 @@ for ((i=0; i<$slen; i++)); do [[ $( ls -dn $VOLDIR/${SERVICES[$i]} | awk '{print $3}') != ${SERVICEUID[$i]} ]] && echo "Chowning $VOLDIR/${SERVICES[$i]} to user ${SERVICEUID[$i]}" && chown -R ${SERVICEUID[$i]}:${SERVICEUID[$i]} $VOLDIR/${SERVICES[$i]} done -<<<<<<< HEAD #Since we are not using net=host, we need to whitelist the subnet in plex. ##TODO## Make this overrideable with commandline argument [[ ! -a $VOLDIR/plex/Plex\ Media\ Server/Preferences.xml ]] && echo Adding subnet to Plex Whitelist... && mkdir -p $VOLDIR/plex/Plex\ Media\ Server/ && \ echo -e "\n" > $VOLDIR/plex/Plex\ Media\ Server/Preferences.xml && chown -R 787:787 $VOLDIR/plex @@ -45,8 +39,3 @@ echo "# Config and directory struture OK! #" echo "#####################################" echo echo "Run docker-compose up -d to start the containers..." -======= -[[ ! -a $VOLDIR/launcher/media-compose.yml ]] && echo "Downloading media-compose.yml.." && curl -sSL https://raw.githubusercontent.com/Adam-Ant/media-server-in-a-box/master/docker-compose.yml > $VOLDIR/launcher/media-compose.yml -echo "Starting services..." -exec docker-compose -p media -f $VOLDIR/launcher/media-compose.yml up -d ->>>>>>> master