Seahub with SERVE_STATIC=True behind apache on different machine

The Server serving Seafile is on private subnet.
There’s a public accessible apache with mod_proxy and ProxyPass /seafile fcgi:/… to the Seahub Service.
seahub runs in fastcgi mode.
seahub shall serve it’s static files because there’s no apache/nginx running on the same machine.

In seahub_settings.py I have:
SERVE_STATIC = True
SITE_ROOT = ‘/seafile/’

That won’t work, because seafile is linking media files to “/media”, which is not below “/seafile” and therefore doesn’t reach seahub.

Thus adding:
MEDIA_URL = ‘/seafile/media/’

That also won’t work, because seafile now is linking media files to “/seafile/media/” while serving media files on “/seafile/seafile/media/” (which is “SITE_ROOT/MEDIA_URL”).

Workaround:

--- seahub/seahub/urls.py.ori	2016-11-16 04:10:25.000000000 +0100
+++ seahub/seahub/urls.py	2016-11-24 13:52:15.604912541 +0100
@@ -303,7 +303,11 @@ if EVENTS_ENABLED:
     )
 
 if settings.SERVE_STATIC:
-    media_url = settings.MEDIA_URL.strip('/')
+    media_url = settings.MEDIA_URL
+    site_root = settings.SITE_ROOT
+    if media_url.startswith(site_root):
+        media_url = media_url[len(site_root):]
+    media_url = media_url.strip('/')
     urlpatterns += patterns('',
         (r'^%s/(?P<path>.*)$' % (media_url), 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
     )

For me this works as expected.

1 Like

It’s Seafile 6.1.1 now and this is still needed - and working, fortunately.

1 Like

I can hardly believe that I’m responding to your message in 2023… But here I am with exactly the same issue. It took me a while to understand the “/seafile/seafile/media/” problem… it’s literally the snake that eats its own tail, and I can’t, for the life of me, make your trick work.

What did you set MEDIA_URL to?

Edit: Actually nevermind… I had SERVE_STATIC at False… Your workaround works perfectly and is a lifesaver. Thank you so much.
My seahub_settings.py now looks like this:

SERVICE_URL = 'https://my.domain.com/seafile'
FILE_SERVER_ROOT = 'https://my.domain.com/seafhttp/'
SERVE_STATIC = True
MEDIA_URL = '/seafile/media/'
COMPRESS_URL = MEDIA_URL
STATIC_URL = MEDIA_URL + 'assets/'
SITE_ROOT = '/seafile/'
LOGIN_URL = '/seafile/accounts/login/'

Oh, good that you have find the solution by yourself. I cannot help you here anymore.
But I wonder it’s still working. What Seafile version do we have nowadays!? :wink:

I’m running version 9.0.10 haha, and your trick still works :joy:
Did you move to a different product?