nginx / docker路由配置

时间:2018-06-09 23:11:04

标签: docker nginx docker-compose

我有一个数字海洋水滴。在它的根目录是以下文件

apps/
 -main/
   -index.html
nginx.conf
docker-compose.yml

我的docker-compose.yml文件包含以下内容

version: '3'

networks:
  proxy:
    external: true
  internal:
    external: false
services:
  traefik:
    image: traefik:alpine
    ports:
      - "8080:8080"
      - "80:80"
      - "443:443"
    restart: always
    labels:
      - logLevel="DEBUG"
      - "traefik.backend=monitor"
      - "traefik.frontend.rule=Host:monitor.domain.com"
      - "traefik.port=8080"
      - "traefik.frontend.entryPoints=http,https"
      - "traefik.enable=true"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "./traefik.toml:/traefik.toml"
      - "./acme.json:/acme.json"
    expose:
      - "8080"
    networks:
      - internal
      - proxy
  custom-badge:
    image: user/app
    environment:
      PORT: 3000
    ports:
      - "3000:3000"
    labels:
      - traefik.enabled=true
      - traefik.backend=app
      - traefik.frontend.rule=Host:app.domain.com
      - traefik.docker.network=proxy
      - traefik.port=3000
    networks:
      - internal
      - proxy
  server:
    image: nginx:alpine
    labels:
      - traefik.enabled=true
      - traefik.backend=
      - traefik.frontend.rule=Host:domain.com
      - traefik.docker.network=proxy
      - traefik.port=80
    volumes:
      - "./apps:/etc/nginx/html:ro"
      - "./nginx.conf:/etc/nginx/nginx.conf:ro"
    command: [nginx-debug, '-g', 'daemon off;']
    depends_on:
      - traefik

和我的nginx.conf

events {
  worker_connections  1024;  ## Default: 1024
}

http {
server {
    listen          80;
    server_name     domain.com www.domain.com;
    location / {
        root  /etc/nginx/html/main;
        proxy_pass  domain.com:8080/;
    }
}
}

问题是,当我运行docker-compose时,一切都启动了,我可以看到所有3个容器都已启动,但是当我去domain.com时,我没有看到我的index.html文件。我做错了什么?

其他域名正常运作:app.domain.com& monitor.domain.com让我觉得nginx配置一定有问题,需要提供哪些文件。

1 个答案:

答案 0 :(得分:1)

你有一个循环 - 删除proxy_pass。 Nginx应该从根文件夹提供数据,而不是将请求代理到另一个服务。