0

我仍然是 Docker n 这样的新手......我正在尝试使用 Nginx 将流量引导到 3 个不同的域/子域,作为测试反向代理如何工作的示例。我能够让一个反应节点工作(在:3000 上默认通过 http://localhost 提供服务),一个 Laravel 容器(在:8000 上是默认并在 phpapp.localhost 提供服务)。这两个都按预期工作。

我正在尝试将我们自己的图像(我们公司自己的,在私人仓库中)与 Apache 和 Dockerfile 中添加的 SSO 模块一起使用。我已经在没有 Nginx 的情况下对其进行了测试,并且使用 $docker run -itd -p 8080:80 hardened-ubuntu-apache (localhost:8080) 可以正常工作。它显示 apache 默认页面(如预期的那样)。那里一切都好。

但是,在我的 docker-compose 中,我将它设置为与 Laravel 容器几乎相同,但它没有像我预期的那样路由。当我转到 hardened.localhost(请参阅下面的 nginx 配置)时,我收到 502 错误。如果我在 docker-compose 时转到 localhost:8080,我会得到 apache 默认页面。就像它出于某种原因忽略了我的子域路由一样。我希望 apache 默认页面显示在 hardened.localhost 子域上……我错过了什么?

在我的终端中,我得到:

[error] 8#8: *46 connect() failed (111: Connection refused) while connecting to upstream, client: 172.21.0.1, server: hardened.localhost,

这是我的 nginx 配置文件

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 1024;
}

http {
       server {
          listen 80;
          server_name localhost 127.0.0.1;

          location / {
              proxy_pass          http://react-for-nginx:3000;
              proxy_set_header    X-Forwarded-For $remote_addr;
          }

      }
      server {
         listen 80;
         server_name phpapp.localhost;

         location / {
             proxy_pass          http://php-for-nginx:8000/;
             proxy_set_header    X-Forwarded-For $remote_addr;
         }

     }
     server {
        listen 80;
        server_name hardened.localhost;

        location / {
            proxy_pass          http://hardened-docker-apache:8080/;
            proxy_set_header    X-Forwarded-For $remote_addr;
        }

    }
}

我的码头工人撰写:

version: '3'

services:

  # Proxies requests to internal services
  reverse-proxy:
    image: nginx:1.17.10
    container_name: reverse-proxy
    depends_on:
        - react-for-nginx
        - php-for-nginx
        - hardened-docker-apache
    volumes:
      - ./reverse-proxy/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - 80:80

  #react service
  react-for-nginx:
    container_name: react-for-nginx
    build:
      context: ./react-for-nginx
      dockerfile: Dockerfile
    ports:
      - 3000:80
    environment:
      - CHOKIDAR_USEPOLLING=true

  #hardend service with SSO
  hardened-docker-apache:
    container_name: hardened-docker-apache
    build:
      context: ./hardened-docker-apache
      dockerfile: Dockerfile
    ports:
      - 8080:80

  # php service
  php-for-nginx:
    container_name: php-for-nginx
    build:
      context: ./php-for-nginx
      dockerfile: Dockerfile
    ports:
      - 8000:80
    restart: on-failure

我在硬化图像“hardened-docker-apache”中的 dockerfile

FROM myprivaterepo/hardened_ubuntu
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get -qq install apache2

RUN apt-get -y install curl
RUN apt-get install -y libapache2-mod-auth-openidc
RUN a2enmod auth_openidc

COPY apache2.conf /etc/apache2/
COPY auth_openidc.conf /etc/apache2/mods-enabled/

EXPOSE 8080
CMD ["apache2ctl", "-D", "FOREGROUND"]
4

0 回答 0