GeoNode / geonode

GeoNode is an open source platform that facilitates the creation, sharing, and collaborative use of geospatial data.
https://geonode.org/
Other
1.45k stars 1.13k forks source link

Struggling to serve geonode on subpath (e.g., /geonode) #11367

Open nhambletCCRI opened 1 year ago

nhambletCCRI commented 1 year ago

Expected Behavior

I was hoping there might be a few variables I could set in .env, and nginx and uWSGI configuration changes (e.g., similar to those described on this previous issue ) so that I could serve geonode from a subpath (e.g., all URLs would be /geonode/whatever, instead of /whatever). I've yet to find a suitable combination.

Actual Behavior

Following the guidance of the previous ticket, and then tweaking .env variables based on code review and observed behavior, it's not clear that it is possible to host from a subpath reliably. Many (but not all?) of the /static urls seem to update-able, but then I haven't yet figured out how to fix some /api and /account URLs.

I've got no particular experience with Django, or uWSGI, so I'm hoping I'm missing some appropriate combination of configuration changes that makes this work, but I've tried several at this point without success.

Steps to Reproduce the Problem

We should be able to use the docker-compose-dev.yml to test the changes, ideally we'd be able to hit localhost/geonode/ and all subsequent addresses would begin with localhost/geonode/.

  1. Change the .env file with the following:
      SITEURL=https://localhost/geonode/ # this is the only line that changes in .env, the others are added
      # FORCE_SCRIPT_NAME=/geonode # this is recommended in the previous ticket, but leads to duplicate path segments if you set STATIC_URL, based on settings.py#L309-L316, so we won't set it here
      STATIC_URL=/geonode/

    In the uwsgi.ini file, add the two following lines:

      mount = /geonode=/usr/src/geonode/geonode/wsgi.py
      manage-script-name = true

    Finally, in scripts/docker/nginx/geonode.conf.envsubst, put /geonode at the front of each location. Additionally, in the final location block (to proxy to the django container), add the two following lines:

      uwsgi_param UWSGI_SCRIPT geonode;
      uwsgi_param SCRIPT_NAME /geonode;
  2. Make sure to rebuild images. The following removes any existing containers and makes new ones (which is probably drastic):
      docker rmi $(docker images | grep geonode | awk '{print $3}')
      docker compose -f docker-compose-dev.yml build --no-cache
  3. Spin up the stack:
      docker compose -f docker-compose-dev.yml up
  4. After it starts, visit https://localhost/geonode in the browser. Observe that while the first request for the base html is ok, and some of the static resources load, though not all (/static/fonts/montserrat.css, /static/mapstore/img/geonode-logo.svg, and, perhaps most importantly, /static/mapstore/configs/localConfig.json).
  5. We can repair some of these with a hack of nginx, just to see if there's any other issues. To be clear, this is not a change we want to make, it's just to see if there's other issues. What we can do is add a redirect for /static to /geonode/static in nginx, with the following new location:
      location /static {
        rewrite ^/(.*)$ /geonode/$1;
      }
    1. That does indeed get further, because localConfig.json loads. The next failing request, though, is one for /api. We can add a similar location rewrite for that (again, not what we want as part of the solution, but a hack to see what else happens), and we actually end up with what appears to be a successful first page load.
    2. The next step would be to "Sign in" with the button at the top right. However, that URL is for /account, so add a rewrite for that, and we get a bit further, and can actually login. Click to add a dataset, and we're taken to a failing /cataloge, so one more rewrite, and we're at least able to upload a kml file.
    3. Things still aren't quite lined up. The "Home" button takes us to just localhost/. The "GeoServer" link from the top-right action button is for "/geoserver" (where ideally it'd be /geonode/geoserver). Going to /geonode/geoserver returns a Tomcat 404 page (we need to add a rewrite in the geoserver location so that nginx strips /geonode out when sending the request down to geoserver).

Specifications

enricofer commented 2 weeks ago

Any news on this topic?