maptiler / tileserver-gl

Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.
https://tileserver.readthedocs.io/en/latest/
Other
2.24k stars 639 forks source link

Better explanation needed of how to use public_url option #363

Open hjrobinson opened 5 years ago

hjrobinson commented 5 years ago

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.

mjcc007 commented 5 years ago

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!

hjrobinson commented 5 years ago

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.

mo-ian-watkins commented 5 years ago

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)

scara commented 4 years ago

For those still fighting w/ this issue like me right now 😉 (npm install tileserver-gl-light@2.5.0), 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

vipyoung commented 4 years ago

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.

Mettbrot commented 1 year ago

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!

odmin4eg commented 11 months ago

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

acalcutt commented 11 months ago

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.

odmin4eg commented 11 months ago

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

francescobianca commented 8 months ago

@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)