Images/Media - 403 error

Long time user of seafile here with this issue - I’ve never had the avatars/custom images work correctly behind a reverse proxy. Seafile itself however works flawless!

404 error on media:

haproxy as the reverse proxy (but I’ve had this issue ever since using Seafile for the last 6+ years even with Caddy as my RP), I’ve tried everything I can think of but simply cannot get it to work.

Seafile-MC installed w/o the use of Caddy from docker:

compose.yaml:

services:
  db:
    image: mariadb:10.11
    container_name: seafile-pro-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=*redacted*  # Required, set the root's password of MySQL service.
      - MYSQL_LOG_CONSOLE=true
      - MARIADB_AUTO_UPGRADE=1
    volumes:
      - /nfs/docker_store/seafile-pro/seafile-mysql/db:/var/lib/mysql  # Required, specifies the path to MySQL data persistent store.
    networks:
      - seafile-pro-net

  memcached:
    image: memcached:1.6.18
    container_name: seafile-pro-memcached
    entrypoint: memcached -m 256
    networks:
      - seafile-pro-net

  elasticsearch:
    image: elasticsearch:8.13.0
    container_name: seafile-elasticsearch
    environment:
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms2g -Xmx2g"
      - "xpack.security.enabled=false"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    mem_limit: 4g
    volumes:
      - /nfs/docker_store/seafile-pro/seafile-elasticsearch/data:/usr/share/elasticsearch/data  # Required, specifies the path to Elasticsearch data persistent store.
    networks:
      - seafile-pro-net
          
  seafile:
    image: docker.seadrive.org/seafileltd/seafile-pro-mc:11.0-latest
    container_name: seafile-pro
    ports:
      - "8088:80"
#     - "443:443"  # If https is enabled, cancel the comment.
    volumes:
      - /nfs/docker_store/seafile-pro/seafile-data:/shared   # Required, specifies the path to Seafile data persistent store.
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD=*redacted*  # Required, the value should be root's password of MySQL service.
      - TIME_ZONE=America/Toronto # Optional, default is UTC. Should be uncomment and set to your local time zone.
      - SEAFILE_ADMIN_EMAIL=*redacted* # Specifies Seafile admin user, default is 'me@example.com'
      - SEAFILE_ADMIN_PASSWORD=*redacted*     # Specifies Seafile admin password, default is 'asecret'
      - SEAFILE_SERVER_LETSENCRYPT=false   # Whether to use https or not
      - SEAFILE_SERVER_HOSTNAME=sea.xxx.xxx # Specifies your host name if https is enabled
      
    depends_on:
      - db
      - memcached
      - elasticsearch
    networks:
      - seafile-pro-net

networks:
  seafile-pro-net:

seahub_settings.py:

# -*- coding: utf-8 -*-
SECRET_KEY = "*redacted*"
SERVICE_URL = "https://sea.xxx.xxx"

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'seahub_db',
        'USER': 'seafile',
        'PASSWORD': '0285fe87-a935-4057-b8c9-3414ce16f3f5',
        '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 = 'America/Toronto'
FILE_SERVER_ROOT = "https://sea.xxx.xxx/seafhttp"
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
ALLOWED_HOSTS = ['.xxx.xxx']
CSRF_TRUSTED_ORIGINS = ['https://sea.xxx.xxx']

haproxy backend passthrough set:

Sorry, for the wall of text. When I started I didn’t realize how complicated this was going to get.

I think for now that your haproxy config is fine since the rest of your sefile web interface is working. Also, your screenshot of the 403 error clearly says it came from nginx, which must be the nginx in the seafile container.

So I looked into how nginx is configured inside the seafile container, and found a couple of interesting things.

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

There’s 2 things to notice here. First, it should be serving files directly from the file system like an old-fashion static pages web server, and second, there is no logging defined here, so there’s no log file that records that it did or did not serve anything from /media (and of course that means nothing recording why). In the other thread you said you checked that the files exist and the permissions should be good, so lets get more info on what problem is happening.

After playing with it a little I see 2 things to try. Unfortunately, the way docker works makes this kind of troubleshooting much harder than it needs to be, but nobody wants to hear my rant about docker, so lets get to it.

What I propose for a first test is, lets get seafile itself to handle these images. The normal seahub process should then log what happens for us, which might give us some idea about what’s going on. I can’t exactly test these steps since I run in podman not docker, so you might need to adjust some of these steps a little.

  1. Get into the seafile container: docker exec -it seafile bash
  2. Edit the nginx config. We are stuck with tools available inside this container, so we’re stuck using vi: vi /etc/nginx/sites-enabled/seafile.nginx.conf
  3. Comment out the /media section so it looks like:
   # location /media {
   # root /opt/seafile/seafile-server-latest/seahub;
   # } 

if you aren’t familiar with vi, you need to start by getting to the first line, then hit i key to switch into insert mode so you can type.

  1. Save and exit vi. To do this you normally hit the esc key to get out of insert mode, then type “:wq” and hit enter to tell it do the commands w to write the file, and q to exit.
  2. If you restart the container, this change will be lost. And there is no init system inside the container (because people like to pretend that docker itself is an init system), so we can’t easily restart nginx. So, lets get the pid of the nginx master proccess: ps aux | grep master
    You are looking for something like “root 22 0.0 0.2 13388 8168 ? S Oct27 0:00 nginx: master process /usr/sbin/nginx”
  3. For me that says the pid is 22. So we will tell pid 22 to reread the conifg file by sending it the HUP signal: kill -s SIGHUP 22
  4. Try again to load one of the pictures. It should now show up in the seahub.access.log or seahub.error.log. For me these looked like:
seahub.access.log:192.168.68.31 10.90.0.4 [30/Oct/2026:14:47:35 -0600] "GET /favicon.ico HTTP/1.1" 404 1214 "https://my.seafile.domain/media/avatars/5/e/6d296dfd86f0216d9b035d71e9f915/resized/256/18d8a154d1b4bfa6e7654bbdfaa606b6.png" "Mozilla/5.0 (X11; Linux x86_64; rv:158.0) Gecko/20100101 Firefox/158.0" 0.056
seahub.access.log:- 10.90.0.4 [30/Oct/2026:14:50:16 -0600] "GET /avatars/5/e/6d296dfd86f0216d9b035d71e9f915/resized/256/18d8a154d1b4bfa6e7654bbdfaa606b6.png HTTP/1.1" 404 10229 "-" "Wget/1.25.0" 0.048

The other option is to just add logging to /media instead of commenting it out. So step 3 would instead look like this:

    location /media {
        root /opt/seafile/seafile-server-latest/seahub;
        access_log /shared/seafile/logs/troubleshooting.access
        error_log  /shared/seafile/logs/troubleshooting.error
    }

And then see what errors you get there. So hopefully it will tell us exactly the path of an image it is trying to load and what error happened when trying to load them.

Well, that was FAR easier than I expected it to be lol

Commenting out the lines for location /media fixed it. And just so you know it does persist a reboot of the container, and shows up in .conf file in my docker files (which I store on my NFS share).

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

So thank you for that, and sorry I had to make you write all that out but I hope this also helps someone later down the line :slight_smile:

Absolutely worth it, since it seems to have helped.

I am surprised. I didn’t expect that it would survive a reboot of the container. It might not survive an upgrade of the container, but I don’t have a way to test that right now.

Honestly, I expected that this would just let us see what errors were happening when trying to access the media files, I didn’t think it would make it work. If an update does break it again, it might be worth trying the extra log lines to see what the problem is. But anyway, I am glad I could help.

I might do that anyway one day when I’m bored lol

But I’m estatic that it actually works! Like I said I’ve been using Seafile for years and no matter how I installed it that’s the one thing that just never worked and I spend hoursing messing around with my config.

This time (this week) I actually moved from community to pro (fresh install, only because my last installation broke by me being stupid) and I started to dig into it once again. So thank you!