错误502使用Nginx通过Docker访问nextcloud

时间:2018-08-10 00:27:14

标签: docker nginx reverse-proxy nextcloud

Heyo!

更新:我想通了,并添加了答案。

我目前正在学习docker,并且编写了一个docker-compose文件,该文件应启动nginx,gitea, nextcloud ,并将它们全部通过域名作为反向代理进行路由。

除了 nextcloud 之外,其他一切都进行得很好。我可以通过localhost:3001访问它,但不能通过nginx反向代理访问它。 使用gitea一切都很好,它可以双向工作。

我得到的错误是:

nginx_proxy     | 2018/08/10 00:17:34 [error] 8#8: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.19.0.1, server: cloud.example.ca, request: "GET / HTTP/1.1", upstream: "http://172.19.0.4:3001/", host: "cloud.example.ca"

docker-compose.yml:

version: '3.1'

services:

  nginx:
    container_name: nginx_proxy
    image: nginx:latest
    restart: always
    volumes: 
// Here I'm swapping out my default.conf for the container's by mounting my 
directory over theirs.
      - ./nginx-conf:/etc/nginx/conf.d
    ports:
      - 80:80
      - 443:443
    networks:
      - proxy

  nextcloud_db:
    container_name: nextcloud_db
    image: mariadb:latest
    restart: always
    volumes:
      - nextcloud_db:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD_FILE: /run/secrets/cloud_db_root
      MYSQL_PASSWORD_FILE: /run/secrets/cloud_db_pass
      MYSQL_DATABASE: devcloud
      MYSQL_USER: devcloud
    secrets:
      - cloud_db_root
      - cloud_db_pass
    networks:
      - database

  gitea_db:
    container_name: gitea_db
    image: mariadb:latest
    restart: always
    volumes:
      - gitea_db:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD_FILE: /run/secrets/cloud_db_root
      MYSQL_PASSWORD_FILE: /run/secrets/cloud_db_pass
      MYSQL_DATABASE: gitea
      MYSQL_USER: gitea
    secrets:
      - cloud_db_root
      - cloud_db_pass
    networks:
      - database

  nextcloud:
    image: nextcloud
    container_name: nextcloud
    ports:
      - 3001:80
    volumes:
      - nextcloud:/var/www/html
    restart: always
    networks:
      - proxy
      - database

  gitea:
    container_name: gitea
    image: gitea/gitea:latest
    environment:
      - USER_UID=1000
      - USER_GID=1000
    restart: always
    volumes:
      - gitea:/data
    ports:
      -  3000:3000
      -  22:22
    networks:
      - proxy
      - database

volumes:
  nextcloud:
  nextcloud_db:
  gitea:
  gitea_db:

networks:
  proxy:
  database:

secrets:
  cloud_db_pass:
    file: cloud_db_pass.txt
  cloud_db_root:
    file: cloud_db_root.txt

我的default.conf挂载到/etc/nginx/conf.d/default.conf

upstream nextcloud {
         server nextcloud:3001;
}

upstream gitea {
         server gitea:3000;
}

server {
       listen 80;
       listen [::]:80;
       server_name cloud.example.ca;

       location / {
                proxy_pass http://nextcloud;
                }
}

server {
       listen 80;
       listen [::]:80;
       server_name git.example.ca;

       location / {
                proxy_pass http://gitea;
                }
}

我当然有我的hosts文件设置,以将域路由到localhost。我做了一些谷歌搜索,但到目前为止我发现的任何内容似乎都不符合我所遇到的情况。预先感谢!

1 个答案:

答案 0 :(得分:0)

长话短说,不能简单地将nextcloud反向代理到端口80。只是不允许。我已经部署了它,并且通过443个证书可以很好地工作! :)