阅读全文解答:docker部署seafile修改80端口映射到主机其他端口,无法访问" /> okPress "Enter" to skip to content

解答:docker部署seafile修改80端口映射到主机其他端口,无法访问

问题见:https://bbs.seafile.com/t/docker-seafile-80/3195/5

但是回答的比较简单,对于刚刚入手 docker 的朋友可能不太熟悉

步骤一

修改部分已用中文标注

#以下为 docker-compose.yml 可适当修改其中的配置
version: '2.0'
services:
  db:
    image: mariadb:10.1
    container_name: seafile-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=db_dev  # Requested, set the root's password of MySQL service.
      - MYSQL_LOG_CONSOLE=true
    volumes:
      - /opt/seafile-mysql/db:/var/lib/mysql  # Requested, specifies the path to MySQL data persistent store.
    networks:
      - seafile-net

  memcached:
    image: memcached:1.5.6
    container_name: seafile-memcached
    entrypoint: memcached -m 256
    networks:
      - seafile-net
          
  seafile:
    image: seafileltd/seafile-mc:latest
    container_name: seafile
    ports:
      - "8088:8088"  # 注意端口在这里更改,如8088
#      - "443:443"  # If https is enabled, cancel the comment.
    volumes:
      - /opt/seafile-data:/shared   # Requested, specifies the path to Seafile data persistent store.
      - /your/path/seafile.nginx.conf.template:/templates/seafile.nginx.conf.template:ro   # 添加这个文件映射
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD=db_dev  # Requested, the value shuold be root's password of MySQL service.
#      - TIME_ZONE=Asia/Shanghai # Optional, default is UTC. Should be uncomment and set to your local time zone.
      - SEAFILE_ADMIN_EMAIL=me@example.com # Specifies Seafile admin user, default is 'me@example.com'.
      - SEAFILE_ADMIN_PASSWORD=asecret     # Specifies Seafile admin password, default is 'asecret'.
      - SEAFILE_SERVER_LETSENCRYPT=false   # Whether use letsencrypt to generate cert.
      - SEAFILE_SERVER_HOSTNAME=seafile.example.com # Specifies your host name.
    depends_on:
      - db
      - memcached
    networks:
      - seafile-net

networks:
  seafile-net:

步骤二

步骤一中的/your/path/seafile.nginx.conf.template 文件从哪里来呢?
官方GitHub上有: 传送门

当然最稳妥的做法是进入容器内部复制一份出来,因为版本可能不一致。拷贝方法:

# 进入容器
docker exec -it seafile /bin/bash
#复制输出的内容,保存成文件
cat /templates/seafile.nginx.conf.template

步骤三

按需修改步骤二中的文件,如修改端口后:

# -*- mode: nginx -*- 本文件已经移除了https相关内容,仅为例子展示
# Auto generated at {{ current_timestr }}


server {
    listen 8088; #这里修改监听端,其他基本不用修改

    server_name {{ domain }};

    client_max_body_size 10m;

    location / {
        proxy_pass http://127.0.0.1:8000/;
        proxy_read_timeout 310s;
        proxy_set_header Host $host;
        proxy_set_header Forwarded "for=$remote_addr;proto=$scheme";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Connection "";
        proxy_http_version 1.1;

        client_max_body_size 0;
        access_log      /var/log/nginx/seahub.access.log seafileformat;
        error_log       /var/log/nginx/seahub.error.log;
    }

    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass http://127.0.0.1:8082;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size 0;
        proxy_connect_timeout  36000s;
        proxy_read_timeout  36000s;
        proxy_request_buffering off;
        access_log      /var/log/nginx/seafhttp.access.log seafileformat;
        error_log       /var/log/nginx/seafhttp.error.log;
    }

    location /seafdav {
        client_max_body_size 0;
        fastcgi_pass    127.0.0.1:8080;
        fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
        fastcgi_param   PATH_INFO           $fastcgi_script_name;

        fastcgi_param   SERVER_PROTOCOL     $server_protocol;
        fastcgi_param   QUERY_STRING        $query_string;
        fastcgi_param   REQUEST_METHOD      $request_method;
        fastcgi_param   CONTENT_TYPE        $content_type;
        fastcgi_param   CONTENT_LENGTH      $content_length;
        fastcgi_param   SERVER_ADDR         $server_addr;
        fastcgi_param   SERVER_PORT         $server_port;
        fastcgi_param   SERVER_NAME         $server_name;

        access_log      /var/log/nginx/seafdav.access.log seafileformat;
        error_log       /var/log/nginx/seafdav.error.log;
    }

    location /media {
        root /opt/seafile/seafile-server-latest/seahub;
    }

    # For letsencrypt
    location /.well-known/acme-challenge/ {
        alias /var/www/challenges/;
        try_files $uri =404;
    }
}

步骤四

最重要的一步,重启你的 docker,非常建议先停止容器,再重新启动。我的版本(seafile-server-7.0.5)使用 restart 并不其作用,浪费了十几分钟排查问题!!!

5 Comments

  1. Reynardli
    Reynardli 2020年3月24日

    使用了 -d 参数,seafile-mamcached 没有运行成功done的标志。
    其他两个seafile 和seafile-mysql 都显示了done

    然后访问域名:端口号 显示拒绝连接请求

    然后我停止了所有容器,重新restart了 docker后。 还是没有办法通过网页访问…
    前问是我哪里操作错了吗… 或者我应该怎么排查哪里出了问题呢…

    (p.s. 如果可以的话,我也有填写自己的邮箱,可以帮我看一下吗?我可以把我的VPS的IP和密码,以及解析的域名地址发给你….)

  2. Reynardli
    Reynardli 2020年3月23日

    博主..我按你的分享设置好了配置文件,但是停掉容器输入命令后,代码就卡在这里不动了,能麻烦帮我看看是哪里出错了吗….
    [root@Reynardli ~]# docker-compose up
    Starting seafile-mysql …
    Starting seafile-mysql … done
    Starting seafile … done
    Attaching to seafile-memcached, seafile-mysql, seafile
    seafile-mysql | 2020-03-23 10:03:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.1.44+maria-1~bionic started.
    seafile-mysql | 2020-03-23 10:03:37+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’
    seafile-mysql | 2020-03-23 10:03:37+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.1.44+maria-1~bionic started.
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] mysqld (mysqld 10.1.44-MariaDB-1~bionic) starting as process 1 …
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: Using mutexes to ref count buffer pool pages
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: The InnoDB memory heap is disabled
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: Compressed tables use zlib 1.2.11
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: Using Linux native AIO
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: Using SSE crc32 instructions
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: Initializing buffer pool, size = 256.0M
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: Completed initialization of buffer pool
    seafile | *** Running /etc/my_init.d/01_create_data_links.sh…
    seafile | *** Running /etc/my_init.d/10_syslog-ng.init…
    seafile | Mar 23 10:03:38 9672d994becb syslog-ng[24]: syslog-ng starting up; version=’3.13.2′
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: Highest supported file format is Barracuda.
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: 128 rollback segment(s) are active.
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: Waiting for purge to start
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.46-86.2 started; log sequence number 2993750
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] Plugin ‘FEEDBACK’ is disabled.
    seafile-mysql | 2020-03-23 10:03:38 139999194343168 [Note] InnoDB: Dumping buffer pool(s) not yet started
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] Server socket created on IP: ‘::’.
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Warning] ‘proxies_priv’ entry ‘@% root@3383dae4832c’ ignored in –skip-name-resolve mode.
    seafile-mysql | 2020-03-23 10:03:38 140000117934080 [Note] mysqld: ready for connections.
    seafile-mysql | Version: ‘10.1.44-MariaDB-1~bionic’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 3306 mariadb.org binary distribution
    seafile | *** Booting runit daemon…
    seafile | *** Runit started as PID 32
    seafile | *** Running /scripts/start.py…
    seafile | Mar 23 10:03:39 9672d994becb cron[38]: (CRON) INFO (pidfile fd = 3)
    seafile | Mar 23 10:03:39 9672d994becb cron[38]: (CRON) INFO (Skipping @reboot jobs — not system startup)
    seafile | [2020-03-23 10:03:39] Skip running setup-seafile-mysql.py because there is existing seafile-data folder.
    seafile | [03/23/2020 10:03:39][upgrade]: The container was recreated, running minor-upgrade.sh to fix the media symlinks
    seafile | [03/23/2020 10:03:39][upgrade]: Running script /opt/seafile/seafile-server-7.0.5/upgrade/minor-upgrade.sh
    seafile |
    seafile | ————————————————————-
    seafile | This script would do the minor upgrade for you.
    seafile | Press [ENTER] to contiune
    seafile | ————————————————————-
    seafile |
    seafile |
    seafile | ——————————
    seafile | migrating avatars …
    seafile |
    seafile |
    seafile | DONE
    seafile | ——————————
    seafile |
    seafile |
    seafile | updating seafile-server-latest symbolic link to /opt/seafile/seafile-server-7.0.5 …
    seafile |
    seafile | DONE
    seafile | ——————————
    seafile |
    seafile |
    seafile | [03/23/20 10:03:39] ../common/session.c(132): using config file /opt/seafile/conf/ccnet.conf
    seafile | Starting seafile server, please wait …
    seafile | ** Message: seafile-controller.c(718): No seafevents.
    seafile |
    seafile | Seafile server started
    seafile |
    seafile | Done.
    seafile |
    seafile | Starting seahub at port 8000 …
    seafile |
    seafile | Seahub is started
    seafile |
    seafile | Done.
    seafile |

    • thinkwei
      thinkwei 2020年3月23日

      看输出没有 error,换一下命令试试
      docker-compose up #一般在终端中调试使用
      docker-compose up -d #表示后台启动,注意【-d】参数

  3. Reynardli
    Reynardli 2020年3月23日

    感谢博主的解答,十分感谢!!写的很详细啦,我这就去试试。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Captcha Code

提示

想看《方方武汉日记》的请到->【小丑人分享】查看所有完整文章