Quickly Set Up OpenStreetMap Tile Server On Ubuntu with OpenMapTiles
OpenStreetMap (OSM) is a user contributed world map that is freely editable. It’s an open-source and self-hosted alternative to Google Maps. Previously I wrote a step-by-step guide to installing your own OpenStreetMap tile server on Ubuntu. It’s a tedious task, I have to admit. Fortunately, there is a new open-source project that makes this process a breeze and In this tutorial I will show you how to quickly set up your own OpenStreeMap tiles server on Ubuntu 22.04/20.04.
Meet OpenMapTiles Map Server
OpenMapTiles Map Server provides 5 different views for the map:
- OpenStreetMap
- Contours
- Hillshade
- Satellite
- Terrain
Maps are powered by the OpenStreetMap data and vector tiles from the OpenMapTiles project.
Prerequisites
Please note that, to download the latest map data and get weekly updates from OpenMapTiles project, you need to purchase their production package, which starts at 1024USD.
Step 1: Set Up OpenStreetMap Tile Server On Ubuntu 22.04/20.04
Log into your Ubuntu 22.04/20.04 server and run the following command to install Docker.
curl -sSL https://get.docker.com/ | sh
Next, download the OpenMapTiles Docker image and run the docker container with the following command.
sudo docker run -d --rm -it -v $(pwd):/data -p 8080:80 klokantech/openmaptiles-server
This docker container will run in daemon mode and listens on localhost:8080. Now you need to visit the web-based wizard to finish installation. If this is a remote server, you need to set up a reverse proxy in order to access to web-based wizard.
Step 2: Set up Reverse Proxy
You can use Apache or Nginx to set up reverse proxy.
Apache
Apache is well-known web server that can also be used as a reverse proxy. Run the following command to install Apache on Ubuntu 22.04/20.04.
sudo apt install apache2
Start Apache and enable auto start.
sudo systemctl start apache2 sudo systemctl enable apache2
To use Apache as a reverse proxy, we need to enable the proxy
modules and the header module.
sudo a2enmod proxy proxy_http headers proxy_wstunnel
Now create a virtual host file for OpenMapTiles Map Server.
sudo nano /etc/apache2/sites-available/openmaptiles.conf
Copy and paste the following lines in to the file. Replace osm.example.com
with your real domain name. You should also add a DNS A record for this sub-domain.
<VirtualHost *:80>
ServerName osm.example.com
ErrorDocument 404 /404.html
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
ErrorLog ${APACHE_LOG_DIR}/osm_error.log
CustomLog ${APACHE_LOG_DIR}/osm_access.log combined
</VirtualHost>
Save and close the file. Then enable this virtual host.
sudo a2ensite openmaptiles.conf
Restart Apache
sudo systemctl restart apache2
Now you can access the OpenMapTiles install wizard via osm.example.com
.
Nginx
Nginx becomes more and more popular these days as a web server and reverse proxy. Install Nginx on Ubuntu 22.04/20.04, 18.10 server with the following command.
sudo apt install nginx
Start Nginx and enable auto start.
sudo systemctl start nginx sudo systemctl enable nginx
Now create a virtual host file for OpenMapTiles.
sudo nano /etc/nginx/conf.d/openmaptiles.conf
Copy and paste the following lines in to the file. Replace osm.example.com
with your real domain name. You should also add a DNS A record for this sub-domain.
server {
listen 80;
server_name osm.example.com;
access_log /var/log/nginx/osm_access.log;
error_log /var/log/nginx/osm_error.log;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Save and close this file. Then test Nginx configuations.
sudo nginx -t
If the test is successful, reload Nginx.
sudo systemctl reload nginx
Now in your browser’s address bar type in osm.example.com
and you should be able to access the web-based install wizard.
Step 3: Enable HTTPS
To encrypt the HTTP traffic, we can enable HTTPS by installing a free TLS certificate issued from Let’s Encrypt. Run the following command to install Let’s Encrypt client (certbot) on Ubuntu 22.04/20.04 server.
sudo apt install certbot
If you use Apache, install the Certbot Apache plugin.
sudo apt install python3-certbot-apache
And run this command to obtain and install TLS certificate.
sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --uir --email [email protected] -d osm.example.com
If you use Nginx, then you need to install the Certbot Nginx plugin.
sudo apt install python3-certbot-nginx
Next, run the following command to obtain and install TLS certificate.
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d osm.example.com
Where
--nginx
: Use the nginx plugin.--apache
: Use the Apache plugin.--agree-tos
: Agree to terms of service.--redirect
: Force HTTPS by 301 redirect.--hsts
: Add the Strict-Transport-Security header to every HTTP response. Forcing browser to always use TLS for the domain. Defends against SSL/TLS Stripping.--staple-ocsp
: Enables OCSP Stapling. A valid OCSP response is stapled to the certificate that the server offers during TLS.
The certificate should now be obtained and automatically installed.
And you can access OpenMapTiles install wizard via HTTPS (https://osm.example.com
).
Step 4: Finish Installation in the Web-based Wizard
First, click the start button.
Next, you can select the map of the whole planet, or a continent, country, etc. Because we are using OpenMapTiles Map Server free edition, only a selected regions are available. Paid items are marked with a lock. I selected the whole planet, which is about 60GB in size.
Then, you can select a style for your map. By default, all styles are selected.
In the next step, you can configure other settings. I just hit the save & run the server
button.
In the last step, you need to sign in at OpenMapTiles.com and get the download key in order to download map data.
If you want to serve the planet map, you can download an outdated map data for free, or purchase a production package (1024 USD) to download up-to-date map data with weekly updates.
Once the data are downloaded, your server with maps is going to be initialized.
And you can see the world map by selecting one of four available styles.
How to Generate Your Own MBTiles
If you don’t want to pay for updated MBTiles, you can generate your own.
Conclusion
I hope this tutorial helped you set up OpenMapTiles Map server on Ubuntu 22.04/20.04 As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂
Hello my name is Miles and several years ago i once asked you how to set this server up, you have done an great job and the process has gotten easier but not by much, wondering why this server has not been simplified yet and why its so hard to setup from scratch, i mean i can install and setup a LAMP server with one simple command, any way still love to visit your site even after all them years.
Now that my basic programming skills are slowly getting better i would like to use a tile server map for a non profet, non commercial in house project.
Is it possible to setup a map server with a blank map (earth size) that i can later use tools like josm to create a fictional map of my own design ?
as i have been searching across the web it seams there are many ways to install and setup the osm server or at least others have, this server would not need to connect or download any data from osm and should be totally self contained. any way i look forward to your replay and would like to discuss this with you more at your convenience….
thank you for all the work you have done with this project and sorry if i started something so long ago lol but it looks like you have handled the task very well.