From 593cc41489966d6e868c9c3ce567f96cb3d92799 Mon Sep 17 00:00:00 2001 From: Adam Dodman Date: Tue, 13 Sep 2016 23:31:48 +0100 Subject: [PATCH] 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