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 a68d22f..5dd4f12 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,20 +43,6 @@ services: - data - container:media restart: always - ports: - - "5050:5050" - - headphones: - image: adamant/headphones - depends_on: - - deluge - - nzbget - volumes_from: - - data - - container:media - restart: always - ports: - - "8181:8181" radarr: image: adamant/radarr @@ -88,9 +65,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 @@ -99,5 +83,11 @@ services: volumes_from: - data restart: always + + web: + image: nginx:alpine + volumes: + - $VOLDIR/launcher/nginx.cfg:/etc/nginx/conf.d/media.conf + restart: always ports: - - "8182:8181" + - "80:80" diff --git a/nginx.cfg b/nginx.cfg new file mode 100644 index 0000000..643b225 --- /dev/null +++ b/nginx.cfg @@ -0,0 +1,94 @@ +resolver 127.0.0.1; +server { + listen 80; + server_name plex.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 ^/$ 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 http://plex: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 http://sickrage:8081; + } +} +server { + listen 80; + server_name nzbget.genie; + + location / { + proxy_pass http://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; + } +} +server { + listen 80; + server_name radarr.genie; + + location / { + proxy_pass http://radarr:7878; + } +} diff --git a/start.sh b/start.sh index 2c4f288..afdda94 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" "326") +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 @@ -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 @@ -28,6 +27,15 @@ 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 -[[ ! -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 +#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 ./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 "#####################################" +echo "# Config and directory struture OK! #" +echo "#####################################" +echo +echo "Run docker-compose up -d to start the containers..."