[Solved] Bad Gateway when accessing/downloading file

I receive this error when attempting to preview a file, or download it directly with seahub. In seahub.lob, this error is printed out each time:

2022-05-22 22:08:49,010 [ERROR] registration.models:326 notify_admins_on_activate_request [Errno 99] Cannot assign requested address
2022-05-22 22:09:24,604 [ERROR] root:1154 prepare_converted_html failed to add_office_convert_task: HTTPConnectionPool(host='office-preview', port=8089): Max retries exceeded with url: /add-task?file_id=b88ab96740ef53249b9d21fb3fa28050842266ba&doctype=doc&raw_path=https%3A%2F%2Fseafile.(censcored).com%2Fseafhttp%2Ffiles%2F56080906-233d-4066-948b-604fbd6d5774%2Fseafile-tutorial.doc (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f534923b430>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
Traceback (most recent call last):
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/urllib3/util/connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1011, in _send_output
    self.send(msg)
  File "/usr/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/urllib3/connection.py", line 205, in connect
    conn = self._new_conn()
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f534923b430>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='office-preview', port=8089): Max retries exceeded with url: /add-task?file_id=b88ab96740ef53249b9d21fb3fa28050842266ba&doctype=doc&raw_path=https%3A%2F%2Fseafile.(censcored).com%2Fseafhttp%2Ffiles%2F56080906-233d-4066-948b-604fbd6d5774%2Fseafile-tutorial.doc (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f534923b430>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/seafile/seafile-server-9.0.5/seahub/seahub/utils/__init__.py", line 1151, in prepare_converted_html
    add_office_convert_task(obj_id, doctype, raw_path)
  File "/opt/seafile/seafile-server-9.0.5/seahub/seahub/utils/__init__.py", line 1107, in add_office_convert_task
    requests.get(url, params, headers=headers)
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/opt/seafile/seafile-server-9.0.5/seahub/thirdpart/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='office-preview', port=8089): Max retries exceeded with url: /add-task?file_id=b88ab96740ef53249b9d21fb3fa28050842266ba&doctype=doc&raw_path=https%3A%2F%2Fseafile.(censcored).com%2Fseafhttp%2Ffiles%2F56080906-233d-4066-948b-604fbd6d5774%2Fseafile-tutorial.doc (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f534923b430>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

I’m trying to readup this log and figure out why there’s an error in name resolution, but I’ve yet to figure it out. Error is persistent whether accessing seafile externally (through nginx proxy pass), locally, across multiple user accounts, etc.

When accessing the file’s direct URL:

Posting config files here:

seafile.conf:

[fileserver]
host = 127.0.0.1
port = 8082
worker_threads = 10

[database]
type = mysql
host = db
port = 3306
user = seafile
password = (redacted)
db_name = seafile_db
connection_charset = utf8

[zip]
windows_encoding = iso-8859-1

ccnet.conf

[General]
SERVICE_URL = https://seafile.(censcored).com

[Database]
ENGINE = mysql
HOST = db
PORT = 3306
USER = seafile
PASSWD = (redacted)
DB = ccnet_db
CONNECTION_CHARSET = utf8

seahub_settings.py

# -*- coding: utf-8 -*-
SECRET_KEY =  (redacted)
SERVICE_URL = 'https://seafile.(censcored).com'
CLOUD_MODE = True

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'seahub_db',
        'USER': 'seafile',
        'PASSWORD': (redacted),
        'HOST': 'db',
        'PORT': '3306',
        'OPTIONS': {'charset': 'utf8mb4'},
    }
}


CACHES = {
    'default': {
        'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
        'LOCATION': 'memcached:11211',
    },
    'locmem': {
        'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
    },
}
COMPRESS_CACHE_BACKEND = 'locmem'
TIME_ZONE = 'EST'
FILE_SERVER_ROOT = 'https://seafile.(censcored).com/seafhttp'
OFFICE_CONVERTOR_ROOT = 'http://office-preview:8089'

Config files seem fine, what does your nginx config file look like?

For nginx, I have it set up to force HTTPS on the default page:

sites-available/default

server {
    server_name _;

	listen 80 default_server;
	listen [::]:80 default_server;

    return 301 https://$host$request_uri;
}

Then for seafile:

sites-available/seafile.(censcored).com

server {
    server_name seafile.(censcored).com;

	listen 443 ssl;
	listen [::]:443 ssl;

    ssl_certificate     (redacted).crt;
    ssl_certificate_key (redacted).key;

    location / {
         proxy_pass         http://127.0.0.1:9080;
         proxy_set_header   Host $host:$server_port;
         proxy_set_header   X-Real-IP $remote_addr;
         proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header   X-Forwarded-Host $server_name;
         proxy_read_timeout  1200s;

         # used for view/edit office file via Office Online Server
         client_max_body_size 0;

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

        send_timeout  36000s;

        access_log      /var/log/nginx/seafhttp.access.log;
        error_log       /var/log/nginx/seafhttp.error.log;
    }
    location /media {
        proxy_pass http://127.0.0.1:9080/media;
        proxy_set_header Host $host:$server_port;
    }
}

Update:

Internal Server Error is irrelevant to the issue, which should have been obvious to me. It has been fixed.

I believe this is an issue with my nginx configuration since Seafile:

  1. Shows me files and file information.
  2. Allows me to create new files directly from the web portal

But:

  1. Downloading a file does not return a file, it results in a bad gateway error from my nginx proxy manager.
  2. I cannot upload files.

Nginx returns this in the error log:

2022/05/27 15:40:58 [error] 638256#638256: *27 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.1, server: seafile.(censcored).com, request: "GET /seafhttp/files/fe1a4503-c1a1-4624-820c-3693cfaad30e/TEsting.docx HTTP/1.1", upstream: "http://127.0.0.1:8082/files/fe1a4503-c1a1-4624-820c-3693cfaad30e/TEsting.docx", host: "seafile.(censcored).com", referrer: "https://seafile.(censcored).com/lib/a1e0a806-fcff-4963-be63-1ab21b08f3c7/file/TEsting.docx"

Replying with solution:

Adding this block to my nginx config worked:

    location ~ / {
            proxy_pass http://127.0.0.1:9080;
    }

I have not figured out why it does, but it does. If anyone would happen to know why please respond.