haiwen / seafile

High performance file syncing and sharing, with also Markdown WYSIWYG editing, Wiki, file label and other knowledge management features.
http://seafile.com/
Other
12.38k stars 1.55k forks source link

502 Bad Gateway (nginx/1.24.0) with LXC and Seafile Docker #2685

Closed Jackovic closed 1 year ago

Jackovic commented 1 year ago

Hello,

I am trying to install Seafile Docker in a LXC container but I get : 502 Bad Gateway in my browser.

I use a web proxy (nginx) to forward to LXC container. It's configuration :

server {
        listen 80 proxy_protocol;
        listen [::]:80 proxy_protocol;

        server_name my.example.org;

        location / {

                include /etc/nginx/proxy_params;
                proxy_pass http://seafile.lxd;

        }

        real_ip_header proxy_protocol;
        set_real_ip_from 127.0.0.1;

}

I have a LXC container named "seafile" with Apache inside, it's configuration :

<VirtualHost *:80>
        ServerName my.example.org

        RewriteEngine On

        <Location /media>
            Require all granted
        </Location>

        # Stuff for seafile server
        ProxyPass /seafhttp http://127.0.0.1:8082
        ProxyPassReverse /seafhttp http://127.0.0.1:8082
        RewriteRule ^/seafhttp - [QSA,L]

        # Stuff for seahub
        SetEnvIf Authorization &quot;(.*)&quot; HTTP_AUTHORIZATION=$1
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8000/
        ProxyPassReverse / http://127.0.0.1:8000/

        ErrorLog ${APACHE_LOG_DIR}/seafile_error.log
        CustomLog ${APACHE_LOG_DIR}/seafile_access.log combined

</VirtualHost>

And, in this LXC container, i have the Seafile Docker running (with a user named "seafile") :

eafile@seafile:~$ docker ps
CONTAINER ID   IMAGE                          COMMAND                  CREATED         STATUS         PORTS                                                                              NAMES
33a724f5e281   seafileltd/seafile-mc:latest   "/sbin/my_init -- /s…"   4 seconds ago   Up 3 seconds   0.0.0.0:8082->8082/tcp, :::8082->8082/tcp, 0.0.0.0:8000->80/tcp, :::8000->80/tcp   seafile
9826e4225e66   memcached:1.5.6                "memcached -m 256"       5 seconds ago   Up 4 seconds   11211/tcp                                                                          seafile-memcached
1517a1d7f3c0   mariadb:10.1                   "docker-entrypoint.s…"   5 seconds ago   Up 4 seconds   3306/tcp                                                                           seafile-mysql

The Nginx version in the Seafile Docker is :

seafile@seafile:/root$ docker exec -it seafile bash
root@33a724f5e281:/opt/seafile# nginx -v
nginx version: nginx/1.24.0

Then I open a browser and enter http://my.example.org and get :

502 Bad Gateway
nginx/1.24.0

So, I guess, there is something wrong between Seafile Docker Nginx and Apache (also tried with Nginx in the LXC container, and same error).

Question : what can I do to solve this issue ? in web-proxy (Nginx 1.18, Ubuntu 22.04) ? in LXC container (Apache 2.4.52, Ubuntu 22.04) ? in Seafile Docker (Nginx 1.24). Any help will be very appreciated. Thank to the Seafile team for this software. Best! ++

Jack

PS : I tested this same configuration WITHOUT LXC and it was working fine. But i decided to use LXC to organize my server.

mlazzarotto commented 1 year ago

I suggest searching Docker container logs for database connection problems.
I initially had the same 502 but that was not because of my http configuration, but rather wrong MariaDB credentials and authorizations.

Jackovic commented 1 year ago

Hi mlazzarotto,

Thank you for the hint. I search in /opt/seafile/logs/seafile.log but found nothing in this file (in the Docker container). Is it the right place to search ?

Here my docker-compose.yml with 'mypassword' as password for MySQL :

version: '2.0'
services:
  db:
    image: mariadb:10.1
    container_name: seafile-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=mypassword  # 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:
      - "8000:80"
      - "8082:8082"
#     - "443:443"  # If https is enabled, cancel the comment.
    volumes:
      - /opt/seafile-data:/shared   # Requested, specifies the path to Seafile data persistent store.
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD=mypassword  # Requested, the value shuold be root's password of MySQL service.
      - TIME_ZONE=Etc/UTC  # Optional, default is UTC. Should be uncomment and set to your local time zone.
      - SEAFILE_ADMIN_EMAIL=dev@example.org # Specifies Seafile admin user, default is 'me@example.com'.
      - SEAFILE_ADMIN_PASSWORD=XXXXXXX     # Specifies Seafile admin password, default is 'asecret'.
      - SEAFILE_SERVER_LETSENCRYPT=false   # Whether to use https or not.
      - SEAFILE_SERVER_HOSTNAME=my.example.org # Specifies your host name if https is enabled.
    depends_on:
      - db
      - memcached
    networks:
      - seafile-net

networks:
  seafile-net:

Then, when I connect to the MySQL database in the Docker container :

root@seafile:~# docker exec -it seafile-mysql /bin/bash
root@6654b3e2514e:/# mysql -uroot -pmypassword
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14871
Server version: 10.1.48-MariaDB-1~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| ccnet_db           |
| information_schema |
| mysql              |
| performance_schema |
| seafile_db         |
| seahub_db          |
+--------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]> use seafile_db
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [seafile_db]> show tables;
+----------------------+
| Tables_in_seafile_db |
+----------------------+
| Branch               |
| FileLockTimestamp    |
| FileLocks            |
| FolderGroupPerm      |
| FolderPermTimestamp  |
| FolderUserPerm       |
| GCID                 |
| GarbageRepos         |
| InnerPubRepo         |
| LastGCID             |
| OrgGroupRepo         |
| OrgInnerPubRepo      |
| OrgQuota             |
| OrgRepo              |
| OrgSharedRepo        |
| OrgUserQuota         |
| Repo                 |
| RepoFileCount        |
| RepoGroup            |
| RepoHead             |
| RepoHistoryLimit     |
| RepoInfo             |
| RepoOwner            |
| RepoSize             |
| RepoStorageId        |
| RepoSyncError        |
| RepoTokenPeerInfo    |
| RepoTrash            |
| RepoUserToken        |
| RepoValidSince       |
| RoleQuota            |
| SeafileConf          |
| SharedRepo           |
| SystemInfo           |
| UserQuota            |
| UserShareQuota       |
| VirtualRepo          |
| WebAP                |
| WebUploadTempFiles   |
+----------------------+
39 rows in set (0.00 sec)

MariaDB [seafile_db]> SELECT * FROM RepoFileCount;
+----+--------------------------------------+------------+
| id | repo_id                              | file_count |
+----+--------------------------------------+------------+
|  1 | 5a4a9308-01c9-4169-a927-c874f420b9b6 |          1 |
|  2 | 81471cf2-08c9-46d2-be24-90dfe6f68870 |          1 |
|  3 | 031ca845-d565-4fa2-a626-cd7cfaf5e23a |       3496 |
|  4 | b3f992c5-d230-4f77-a997-e6fa624f01b5 |      10509 |
|  6 | cbee47bb-a0f8-47b6-b035-05ed56db562d |       3174 |
|  7 | aff3a1bf-f200-459d-aa46-a90a7ffd66d8 |          1 |
|  8 | c39fd3e0-4133-4386-94a7-e2d8d5958b69 |          1 |
+----+--------------------------------------+------------+
7 rows in set (0.00 sec)

It seems everything is in right place and I can (and Seafile too) have an access to databases with root/mypassword ?

However i found in /var/log/nginx/seahub.error.log :

2023/06/24 23:23:07 [error] 68#68: *290 connect() failed (111: Connection refused) while connecting to upstream, client: 172.29.0.1, server: my.example.org, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "my.example.org"
2023/06/24 23:23:07 [error] 68#68: *290 connect() failed (111: Connection refused) while connecting to upstream, client: 172.29.0.1, server: my.example.org, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8000/favicon.ico", host: "my.example.org", referrer: "http://my.example.org/"

Maybe it is related to my issue ? As I wrote at the end of my last message, the same configuration WITHOUT LXC was working nicely before (same docker-compose.yml). I followed the section "Backup and recovery" on https://manual.seafile.com/docker/deploy_seafile_with_docker/ to copy database and data.

Any recommendations/tests I can do ? Best! ++

Jack

mlazzarotto commented 1 year ago

So, I guess, there is something wrong between Seafile Docker Nginx and Apache (also tried with Nginx in the LXC container, and same error).

Likely an issue with the redirection.
Do you have the same error code by accessing Apache directly from your browser?

Jackovic commented 1 year ago

On Apache, disabling 001-seafile.conf : # a2dissite 001-seafile.conf

which contains :

<VirtualHost *:80>
        ServerName my.example.org

        RewriteEngine On

        <Location /media>
            Require all granted
        </Location>

        # Stuff for seafile server
        ProxyPass /seafhttp http://127.0.0.1:8082
        ProxyPassReverse /seafhttp http://127.0.0.1:8082
        RewriteRule ^/seafhttp - [QSA,L]

        # Stuff for seahub
        SetEnvIf Authorization &quot;(.*)&quot; HTTP_AUTHORIZATION=$1
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8000/
        ProxyPassReverse / http://127.0.0.1:8000/

        ErrorLog ${APACHE_LOG_DIR}/seafile_error.log
        CustomLog ${APACHE_LOG_DIR}/seafile_access.log combined

</VirtualHost>

and enabling 000-default.conf : # a2ensite 000-default

which contains :

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

And going to http://my.example.org, I can see the default 'Apache2 Default Page' : 'It `works!' This is the default welcome page used to test the correct operation of the Apache2 server after installation on Ubuntu systems. It is based on the equivalent page on Debian, from which the Ubuntu Apache packaging is derived. If you can read this page, it means that the Apache HTTP server installed at this site is working properly. You should replace this file (located at /var/www/html/index.html) before continuing to operate your HTTP server...

So no, i don't have the same error code when I am accessing a web page in Apache in my LXC container. Can I try something else to help ? ++

Jack

Jackovic commented 1 year ago

Some news...

I have removed Apache on the LXC container, it was redundant. So, in docker-compose, I just change :

    ports:
      - "8000:80"
      - "8082:8082"
#     - "443:443"  # If https is enabled, cancel the comment.

to :

    ports:
      - "80:80"
#     - "443:443"  # If https is enabled, cancel the comment.

but I had always this "502 Bad Gateway" (nginx/1.24.0) with the same error in /var/log/nginx/seahub.error.log

I was very annoyed to discover after (in the docker container) :

# netstat -tuplen
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      0          145513711  33/nginx: master pr 
tcp        0      0 127.0.0.11:33327        0.0.0.0:*               LISTEN      0          145510108  -                   
udp        0      0 127.0.0.11:47278        0.0.0.0:*                           0          145510107  -                   

No trace of Seafile listening on 8000 and 8082 !!! So my problem is here. My migration of Seafile Docker was a failure. And Marco assumption seems to be good because after :

$ docker logs seafile
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
...

After granting user seafile (following description here : https://manual.seafile.com/docker/6.3_upgrade_to_7.0/) I have another problem :

$ docker logs -f seafile
*** Running /etc/my_init.d/01_create_data_links.sh...
*** Booting runit daemon...
*** Runit started as PID 22
*** Running /scripts/enterpoint.sh...
2023-06-26 23:20:32 Nginx ready 
2023-06-26 23:20:32 This is an idle script (infinite loop) to keep container running. 
[06/26/2023 23:20:32][upgrade]: Running script /opt/seafile/seafile-server-10.0.1/upgrade/upgrade_9.0_10.0.sh

-------------------------------------------------------------
This script would upgrade your seafile server from 9.0 to 10.0
Press [ENTER] to contiune
-------------------------------------------------------------

Updating seafile/seahub database ...

[INFO] You are using MySQL
[INFO] updating ccnet database...
[INFO] updating seafile database...
[INFO] updating seahub database...
Done

migrating avatars ...

Done

updating /opt/seafile/seafile-server-latest symbolic link to /opt/seafile/seafile-server-10.0.1 ...

-----------------------------------------------------------------
Upgraded your seafile server successfully.
-----------------------------------------------------------------

Starting seafile server, please wait ...

** (process:111): WARNING **: 23:20:33.073: seafile-controller.c(586): invalid config_dir: /opt/seafile/ccnet

** (process:111): WARNING **: 23:20:33.073: seafile-controller.c(64): seaf-controller exited with code 1

Failed to start seafile server
[2023-06-26 23:20:32] Skip running setup-seafile-mysql.py because there is existing seafile-data folder.
[2023-06-26 23:20:32] Running scripts /opt/seafile/seafile-server-10.0.1/upgrade/upgrade_9.0_10.0.sh
Traceback (most recent call last):
  File "/scripts/start.py", line 95, in <module>
    main()
  File "/scripts/start.py", line 80, in main
    call('{} start'.format(get_script('seafile.sh')))
  File "/scripts/utils.py", line 70, in call
    return subprocess.check_call(*a, **kw)
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '/opt/seafile/seafile-server-10.0.1/seafile.sh start' returned non-zero exit status 1.

But this is another problem. Thank you Marco for your help. ++

Jack

langren1353 commented 1 year ago

Some news...

I have removed Apache on the LXC container, it was redundant. So, in docker-compose, I just change :

    ports:
      - "8000:80"
      - "8082:8082"
#     - "443:443"  # If https is enabled, cancel the comment.

to :

    ports:
      - "80:80"
#     - "443:443"  # If https is enabled, cancel the comment.

but I had always this "502 Bad Gateway" (nginx/1.24.0) with the same error in /var/log/nginx/seahub.error.log

I was very annoyed to discover after (in the docker container) :

# netstat -tuplen
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      0          145513711  33/nginx: master pr 
tcp        0      0 127.0.0.11:33327        0.0.0.0:*               LISTEN      0          145510108  -                   
udp        0      0 127.0.0.11:47278        0.0.0.0:*                           0          145510107  -                   

No trace of Seafile listening on 8000 and 8082 !!! So my problem is here. My migration of Seafile Docker was a failure. And Marco assumption seems to be good because after :

$ docker logs seafile
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
waiting for mysql server to be ready: %s (1045, "Access denied for user 'seafile'@'192.168.112.4' (using password: YES)")
...

After granting user seafile (following description here : https://manual.seafile.com/docker/6.3_upgrade_to_7.0/) I have another problem :

$ docker logs -f seafile
*** Running /etc/my_init.d/01_create_data_links.sh...
*** Booting runit daemon...
*** Runit started as PID 22
*** Running /scripts/enterpoint.sh...
2023-06-26 23:20:32 Nginx ready 
2023-06-26 23:20:32 This is an idle script (infinite loop) to keep container running. 
[06/26/2023 23:20:32][upgrade]: Running script /opt/seafile/seafile-server-10.0.1/upgrade/upgrade_9.0_10.0.sh

-------------------------------------------------------------
This script would upgrade your seafile server from 9.0 to 10.0
Press [ENTER] to contiune
-------------------------------------------------------------

Updating seafile/seahub database ...

[INFO] You are using MySQL
[INFO] updating ccnet database...
[INFO] updating seafile database...
[INFO] updating seahub database...
Done

migrating avatars ...

Done

updating /opt/seafile/seafile-server-latest symbolic link to /opt/seafile/seafile-server-10.0.1 ...

-----------------------------------------------------------------
Upgraded your seafile server successfully.
-----------------------------------------------------------------

Starting seafile server, please wait ...

** (process:111): WARNING **: 23:20:33.073: seafile-controller.c(586): invalid config_dir: /opt/seafile/ccnet

** (process:111): WARNING **: 23:20:33.073: seafile-controller.c(64): seaf-controller exited with code 1

Failed to start seafile server
[2023-06-26 23:20:32] Skip running setup-seafile-mysql.py because there is existing seafile-data folder.
[2023-06-26 23:20:32] Running scripts /opt/seafile/seafile-server-10.0.1/upgrade/upgrade_9.0_10.0.sh
Traceback (most recent call last):
  File "/scripts/start.py", line 95, in <module>
    main()
  File "/scripts/start.py", line 80, in main
    call('{} start'.format(get_script('seafile.sh')))
  File "/scripts/utils.py", line 70, in call
    return subprocess.check_call(*a, **kw)
  File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '/opt/seafile/seafile-server-10.0.1/seafile.sh start' returned non-zero exit status 1.

But this is another problem. Thank you Marco for your help. ++

Jack

mark一下,最终原因是因为xxxx/seafile/datas/seafile/ccnet文件夹不存在,这个是一个空目录 我使用了rclone来备份,但是rclone直接跳过了空目录导致的这个问题,创建一下这个空目录就可以解决,非seafile的问题