I kind of avoided using Nginx because it didn't match my needs across the years. But now, I find myself forced to start using it.
Goal: to have a private "ho.me" domain and with it, to go to my 2 containers:
- /t to my Transmission server container (192.168.50.30:9091);
- /tv to my Plex media server container (192.168.50.30:32400/web).
Issue: "ho.me" forwards me to where also /t does but I want "ho.me" to just show my static index.html and not take me to the Transmission server. What am I doing wrong?
In this raw phase, I'm using a Bash script, a Dockerfile and 2 .conf files. In order to create and run the nginx container I'm running these files in this order:
- configure_and_run.sh:
#!/bin/bash
#Goal: configure all files and run the nginx-reverse-proxy container
#1. Update system
sudo apt-get update
sudo apt-get upgrade -y
#2. Get rid of unnecesary remaining software
sudo apt-get autoremove -y --purge
#3. Create a folder that holds the configuration for ho.me VirtualHost
sudo mkdir /apps/docker/apacheconf/sites
#4. Copy the initial ho.me VirtualHost home.conf file
sudo cp -r home.conf /apps/docker/apacheconf/sites/
#5. Create a folder that holds the html files of the web server
sudo mkdir /apps/docker/apacheconf/htmlfiles
#6. Copy the initial index.html so we can test it works
sudo cp -r index.html /apps/docker/apacheconf/htmlfiles/
#Build the nginx-reverse-proxy via the existing
docker build -t nginx-reverse-proxy .
#Run the container
docker container run \
--publish 80:80 \
-d --name nginxrp \
-v /apps/docker/apacheconf/sites:/usr/local/apache2/conf/sites \
-v /apps/docker/apacheconf/htmlfiles:/usr/local/apache2/home \
nginx-reverse-proxy
- home.conf:
<VirtualHost *:80>
ServerName www.ho.me
ServerAlias ho.me
ServerAdmin admin@home.com
DocumentRoot /usr/local/apache2/home
<Directory "/usr/local/apache2/home">
Order allow,deny
AllowOverride All
Allow from all
Require all granted
</Directory>
LoadModule ssl_module modules/mod_ssl.so
SSLProxyEngine on
RequestHeader set X-Forwarded-Proto “https”
RequestHeader set X-Forwarded-Port “443”
ErrorLog logs/home-error.log
CustomLog logs/home-access.log combined
</VirtualHost>
- default.conf:
# Complete Nginx Docker reverse proxy config file
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
# The Transmission torrent client redirection
location /t {
proxy_pass http://192.168.50.30:9091;
}
# The Plex media server redirection
location /tv/ {
rewrite /tv(/.*) $1 break;
proxy_pass http://192.168.50.30:32400;
proxy_http_version 1.1;
proxy_set_header Accept-Encoding "";
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
sub_filter '/web/' '/tv/web/';
sub_filter_types *;
sub_filter_once off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
- simple Docker file:
FROM nginx:latest
COPY default.conf /etc/nginx/conf.d/default.conf
COPY index.html /usr/share/nginx/html/