为什么nginx容器重定向我的私人域到不同的位置?



我避免使用Nginx,因为多年来它不符合我的需求。但现在,我发现自己不得不开始使用它。

:有一个私人的"ho.me";域和它,去我的两个容器:

  1. /t到我的传输服务器容器(192.168.50.30:9091);
  2. /tv到我的Plex媒体服务器容器(192.168.50.30:32400/web)。

问题:"ho.me"转发我到哪里也/它做,但我想"何。我"只显示我的静态index.html,而不带我到传输服务器。我做错了什么?

在这个原始阶段,我使用一个Bash脚本,一个Dockerfile和2个.conf文件。为了创建和运行nginx容器,我按以下顺序运行这些文件:

  1. 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>
    
    4
  • 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;
    }
    } 
    }
    
    1. 简单Docker文件:
    FROM nginx:latest
    COPY default.conf /etc/nginx/conf.d/default.conf
    COPY index.html /usr/share/nginx/html/
    

    解决方案@HansKilian注意到我在"/"上缺少了一个右花括号在我的nginx配置中的位置。

    最新更新