与Nginx在不同路径中的Docker容器

时间:2017-11-28 14:53:56

标签: nginx docker-compose

我试图设置Nginx将两个应用程序(一个Express和一个Dockpress容器中的Wordpress)路由到他们自己的公共路径。到目前为止,它一次只能用于一个容器,但是从本地端口到它们的公共路径的路由都没有,而且我有点想法。任何帮助或想法接近这一点非常感激。

继承人我的nginx配置:

server {
  listen 80;
  proxy_set_header Host $http_host;
  proxy_set_header X-Read-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_redirect off;

  location /api {
    proxy_pass  http://0.0.0.0:3000;
  }

  location /blog {
    proxy_pass  http://0.0.0.0:8000;
  }
}

Docker撰写:

version: '3.2'
services:
  api-service:
    restart: always
    depends_on:
      - wordpress-service
    image: mhart/alpine-node:latest
    build: .
    networks:
      main:
        aliases:
          - api-service
  wordpress-service:
    restart: always
    depends_on:
      - db
    image: wordpress:latest
    working_dir: /var/www/html
    volumes:
      - wordpress:/var/www/html/wp-content
    expose:
      - "8000"
    networks:
      main:
        aliases:
          - wordpress-service
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      main:
        aliases:
          - db
volumes:
  db_data:
  wordpress:
networks:
  main:

0 个答案:

没有答案