tileserver-gl icon indicating copy to clipboard operation
tileserver-gl copied to clipboard

Better explanation needed of how to use public_url option

Open hjrobinson opened this issue 5 years ago • 10 comments

I've been trying to utilize the public_url option but every time I use the -u flag I get the following error:

TypeError: publicUrl.lastIndexOf is not a function

Does proper use of this involve the config.json file? I've experimented by adding "public_url":"myDomainName" to the options in the file to no avail.

My end goal is access the tile server from my AWS ec2 instance which is windows 2012 R2. Port 8080 (which I've enabled inbound access to) will not load the server's page from the web.

Perhaps I misunderstand the purpose of the public_url option. Any help is appreciated. Thanks.

hjrobinson avatar May 27 '19 05:05 hjrobinson

I have been trying to use the public_url option on the docker, but i don't not how can i use! please give an example for docker , Thanks!

mjcc007 avatar Jun 13 '19 12:06 mjcc007

This might get you by until there's a better explanation:

https://schernthanner.de/vector-tile-serving-some-introductory-thoughts-hints-for-a-fast-way-to-serve-vector-tiles

I used Ubuntu Server 18.04 LTS (HVM), SSD Volume Type from Amazon Web Services and got it going. I'm not sure how a public url figures into this but you can at least access your server from the web on your chosen port.

hjrobinson avatar Jun 15 '19 16:06 hjrobinson

Public_URL option doesn't appear to be documented yet here: https://tileserver.readthedocs.io/en/latest/usage.html#getting-started

But for Docker we simply add the text to the command line as:

--public_url /path/to/serve/from/

Note, that is a double minus

This gives us a command line in total of:

docker run --rm -dit -v $(pwd):/data -p 8080:80 klokantech/tileserver-gl:v3 --verbose --config config.json --public_url /path/to/serve/from/

And then the Tileserver-GL homepage is at:

http://servername:8080/path/to/serve/from/

Where you can see your styles, usual stuff. Raster viewers work fine but the Vector ones do not for some reason (might be our setup)

mo-ian-watkins avatar Oct 11 '19 15:10 mo-ian-watkins

For those still fighting w/ this issue like me right now 😉 (npm install [email protected]), the fix is https://github.com/maptiler/tileserver-gl/commit/e8134dfeb0ec39297b97e9a020b52c9af00d25b0 i.e. fixed in 2.6.0 not (yet???) available via npm.

HTH, Matteo

scara avatar Jan 18 '20 17:01 scara

I has a similar issue recently and what eventually worked for me is to provide the full public address:
docker run --rm -it -v $(pwd):/data -p 8080:80 klokantech/tileserver-gl:v3 --verbose --config config.json --public_url https://mydomain.com/tiles

My tileserver-gl was running behind nginx which I configured via (location) to forward anything after /tiles to my docker instance. The full path, including https was important to get rid of some browser errors related to serving mixed-content due to tileserver-gl generating some urls in http. Hope this would help you guys.

vipyoung avatar Mar 03 '20 05:03 vipyoung

I has a similar issue recently and what eventually worked for me is to provide the full public address: docker run --rm -it -v $(pwd):/data -p 8080:80 klokantech/tileserver-gl:v3 --verbose --config config.json --public_url https://mydomain.com/tiles

My tileserver-gl was running behind nginx which I configured via (location) to forward anything after /tiles to my docker instance. The full path, including https was important to get rid of some browser errors related to serving mixed-content due to tileserver-gl generating some urls in http. Hope this would help you guys.

Thank you for this! You may use the command: --public_url https://mydomain.com/tiles option if you are working with docker compose (trick )

EDIT: You may also use a relative path and it works without the url, this makes me very happy --public_url /tiles!

Mettbrot avatar Jul 31 '23 13:07 Mettbrot

I managed to launch a container with an indication of the public directory # docker run -it -v $(pwd):/data -p 8080:8080 maptiler/tileserver-gl *.mbtiles --public_url /map

location ~ ^/map(/.*)?$ {
  proxy_pass http://127.0.0.1:8080$1;
}

everything worked except for vector tiles, and I would really like to figure out what's wrong

vector vector2

odmin4eg avatar Dec 06 '23 10:12 odmin4eg

I may be wrong, but think you also need to include the domain in the public url, like

--public_url http://foo.lan/map or if you have a https proxy set up --public_url https://foo.lan/map

Based on the errors you are getting it seems like maplibre-gl-js doesn't like the relative links the tileserver-gl json is providing when you don't provide a full url for public_url. If you look at how those urls are generated at https://github.com/maptiler/tileserver-gl/blob/master/src/utils.js#L71-L78 you can see it doesn't append protocol or domain when you specify public_url , so I think you have to specify it yourself.

acalcutt avatar Dec 06 '23 13:12 acalcutt

no, I tried, the result is the same, I set the full path docker run -it -v $(pwd):/data -p 8080:8080 maptiler/tileserver-gl *.mbtiles --public_url https://data.site.xx/map/

as a result, I solved the problem by creating a subdomain map.domain.xx everything worked on it

odmin4eg avatar Dec 07 '23 03:12 odmin4eg

@odmin4eg I also had the same error as you. I have a server that serves me offline maps but if I accessed from an ip other than the one specified in the public url it would no longer load the maps. I solved it by modifying the mapbox library.

const lt = function(t, r) {
    if (!(/^file:/.test(n = t.url) || /^file:/.test(ot()) && !/^\w+:/.test(n))) {
        if (e.fetch && e.Request && e.AbortController && e.Request.prototype.hasOwnProperty("signal"))
            return function(t, r) {
                /* Fix per url mappe relativi*/
                if (!t.url.startsWith('http')) {
                    t.url = new URL(t.url,location.origin);
                }

In this way I overwrite the url with the one taken from the browser (if the http prefix is not passed but the relative path is)

francescobianca avatar Mar 20 '24 12:03 francescobianca