singularityhub / sregistry

server for storage and management of singularity images
https://singularityhub.github.io/sregistry
Mozilla Public License 2.0
103 stars 42 forks source link

Configuring base_url for sregistry when deployed behind an Apache reverse proxy on port 80 #441

Open imerelli opened 11 months ago

imerelli commented 11 months ago

Hello,

I'm trying to deploy sregistry behind an Apache reverse proxy on port 80 and have run into some issues with the application's URLs. I've set up Apache to route requests from /sregistry to the sregistry application running on port 81, as I have other sites and configurations on my server.

Here's my current Apache configuration:

<VirtualHost *:80>

    # Enable rewrite module
    RewriteEngine On

    # Redirect /sregistry to /sregistry/
    RewriteRule ^/sregistry$ /sregistry/ [R=301,L]

    # Proxy requests to sregistry
    RewriteRule ^/sregistry/(.*)$ http://localhost:81/$1 [P,L]

    ProxyPreserveHost On
    ProxyRequests Off

    # Handle reverse proxying
    ProxyPassReverse /sregistry/ http://localhost:81/

    # Specific rules for static resources
    ProxyPass /static/ http://localhost:81/static/
    ProxyPassReverse /static/ http://localhost:81/static/
</VirtualHost>

With this configuration, I'm able to access the sregistry homepage fine. However, some internal application links, like /collections and /login, are broken because they don't seem to be aware of the /sregistry prefix.

I assume there's a need to adjust a base_url or similar setting in the sregistry configuration to inform it of the /sregistry prefix. Could you provide guidance on how to properly configure this or point out if there's any step I might be overlooking?

Thank you for your assistance!

vsoch commented 11 months ago

The setup is built with Nginx, so first I’d start with modifying that configuration first (instead of putting it behind a different webserver). Then if you want to tweak the baseurl it should be in settings.py, and you can build a custom image.

imerelli commented 11 months ago

Hi vsoch, thank you for the suggestion. On the server I have apache, so I have to pass through it using a simple rewrite rule (I didn't touched nginx). However, I changed these settings and more or less it works:

urlpatterns = [ url(r"^sregistry/admin/", admin.site.urls), url(r"^sregistry/", include(base_urls)), url(r"^sregistry/api/", include(api_urls)), url(r"^sregistry/", include(library_urls)), # Sylabs library API - includes v1 and v2 (damn) url(r"^sregistry/api/schema/$", schema_view), url(r"^sregistry/api/docs/", include_docs_urls(title=API_TITLE, description=API_DESCRIPTION)), url(r"^sregistry/", include(main_urls)), url(r"^sregistry/", include(user_urls)), url(r"^sregistry/sitemap.xml$", index, {"sitemaps": sitemaps}, name="sitemap"), url(r"^sregistry/sitemap-(?P

.+).xml$", sitemap, {"sitemaps": sitemaps}), url(r"^sregistry/django-rq/", include("django_rq.urls")), ]

But I don't see css and images. Any suggestion about this?

vsoch commented 11 months ago

You likely want to look at your console logs to see the path that is being tried, and adjust accordingly. The roots are defined here: https://github.com/singularityhub/sregistry/blob/675fb4daaef5151132f2ef0947b85a6e255e24b7/shub/settings.py#L549-L556