Skip to content

Internal, External and Reverse Proxy Web Servers

granny edited this page May 2, 2024 · 9 revisions

Internal Server

Pl3xMap ships with an internal web server that comes all the bells and whistles you'll need to get your map online and sharable. See the config for it here.

The default address to bind to is 0.0.0.0 which binds to all interfaces the machine is assigned to. Do not set this to your server's public IP or domain! This should not be changed if you don't know what it does.

The default port is 8080. Ensure the port you use is open to outside internet connections so others can access the map. Once that's done you can forward it's traffic to port 80 (if no other services are using it) which will allow users to use the map without specifying a port in the address bar.

By default, the internal web server is enabled for your convenience.
If you need more advanced features, such as SSL, you'll need to use an external web server or a reverse proxy.

⚠️ Setting up an external web server or a reverse proxy is for advanced users only! ⚠️

External Server

Some users may want to disable the internal web server to use their own external web server.
If your external web server can't access Pl3xMap's tiles, you can set up a reverse proxy. Otherwise, follow this section to route all traffic through an external web server.

This guide is written for Debian-based operating systems. However, much of it still applies for Linux-based operating systems.

Before you begin, ensure you have:

  1. root/sudo access on the machine
  2. a Linux distro with apt (Debian, Ubuntu, etc.)
  3. TCP ports 80 and/or 443 available and open
  4. already ran Pl3xMap once with the internal web server enabled
  5. the Minecraft server is currently offline

There are specific sections for a variety of web servers.

Apache2

<VirtualHost *:80>
    ServerName example.com
    ServerAdmin [email protected]
    DocumentRoot "/var/www/"
    <Directory "/var/www/">
        Options -Indexes +FollowSymLinks -MultiViews
        AllowOverride All
        Require all granted
    </Directory>
    <FilesMatch "(\.gz)$">
        Header set Content-Encoding gzip
        Header append Vary Accept-Encoding
    </FilesMatch>
</VirtualHost>

NGINX

This part of the guide will show you how to serve the map with NGINX without a reverse proxy.

First install NGINX and go through the initial setup.

Then copy the files from the default Pl3xMap web directory (plugins/Pl3xMap/web) to the web server's web root directory (/var/www/<YOUR_DOMAIN>)
You can do this by creating a symlink from the Pl3xMap web directory to this folder or by copying the files and updating the path in Pl3xMap's config.

Use this snippet for your website-config:

server {
  listen 80; # listens on port 80
  listen [::]:80; # listen to all addresses on port 80
  server_name <YOUR_DOMAIN>; # the name (domain) of the server

  root /var/www/<YOUR_DOMAIN>; # sets the root dir
  index index.html; # the index file name

  # Pl3xMap uses statically compressed files for extensive data
  location ~ \.gz$ {
    gzip off; # Ensure nginx doesn't double-compress
    add_header Content-Encoding gzip;
  }

  # Pl3xMap uses Server Sent Events through the /sse route for realtime marker updatess
  location /sse {
    chunked_transfer_encoding off;
    proxy_buffering off;
    proxy_cache off;
    proxy_pass http://<SERVER IP>:<Pl3xMap Internal Web Server Port>;
  }
}

This will create a new site config for Pl3xMap. As usual, replace <YOUR_DOMAIN> with your domain.

Restart NGINX and start your Minecraft server, make sure everything is running correctly.
Navigating to https://<YOUR_DOMAIN>/ should now show you the map!
After you've completed this, follow Enabling SSL.

Caddy

This part of the guide will show you how to serve the map with Caddy without a reverse proxy.

First install Caddy and go through the initial setup: https://caddyserver.com/docs/, make sure to setup a caddyfile.

Add this snippet to your caddyfile:

<YOUR_DOMAIN> {
	root * </path/to/plugins/Pl3xMap/web>

	# Pl3xMap uses statically compressed files for extensive data
	@gz path *.gz
	header @gz Content-Encoding gzip

	# Pl3xMap uses Server Sent Events through the /sse route for realtime marker updatess
	reverse_proxy /sse* localhost:8084 {
		flush_interval -1
	}

	file_server
}

This will create a new site config for Pl3xMap. As usual, replace <YOUR_DOMAIN> with your domain.

This will tell Caddy:

  • What domain it should use.
  • The folder where it should look for your files
  • And finally how it should handle a few of Pl3xmap's special compressed files

Reload your caddyfile, navigating to https://<YOUR_DOMAIN>/ should now show you the map!
Caddy will automatically handle the HTTPS authentication for your webpage, no need to setup SSL yourself!

Reverse Proxy

"A reverse proxy is a server that sits in front of one or more web servers, intercepting requests from clients."
- Cloudflare

This route will allow the use of a domain and existing web server without modifying Pl3xMap's internal web server.

Before you begin, ensure you have:

  • root/sudo access on the machine
  • a Linux distro with apt (Debian, Ubuntu, etc.)
  • TCP ports 80 and 443 available and open
  • Pl3xMap's internal server enabled and functional

There are specific sections for a variety of web servers.

NGINX

This part of the guide will show you how to serve the map with NGINX with a reverse proxy.

First install NGINX and go through the initial setup.

Use this snippet for your website-config:

server {
  listen 80; # listens on port 80
  listen [::]:80; # listen to all addresses on port 80

  server_name <YOUR_DOMAIN>; # the name of the server

  location / {
    proxy_pass http://<MAP_IP>:<MAP_PORT>; # reverse proxy to Pl3xMap instance
  }
}

This will create a new site config for Pl3xMap. As usual replace anything within angle brackets < > to the values that apply to you.

Start your Minecraft server, make sure Pl3xMap's internal server is running.
Navigating to https://<YOUR_DOMAIN>/ should now show you the map!
After you've completed this, follow Enabling SSL.

Caddy

This part of the guide will show you how to serve the map with Caddy with a reverse proxy.

First install caddy and go through the initial setup: https://caddyserver.com/docs/, make sure to setup a caddyfile.

Add this snippet to your caddyfile:

<YOUR_DOMAIN>

reverse_proxy 127.0.0.1:<pl3xmap_port>

This will create a new site config for Pl3xMap. As usual, replace <YOUR_DOMAIN> with your own domain.

Reload your caddyfile & start your Minecraft server, make sure Pl3xMap's internal server is running.
Navigating to https://<YOUR_DOMAIN>/ should now show you the map!
Caddy will automatically handle the HTTPS authentication for your webpage, no need to setup SSL yourself!

Enabling SSL

This section assumes that you have:

SSL is important to keep the users accessing your site secure.
Assuming you're running on a Ubuntu distro, you can get a free SSL certificate by running the commands below:

$ sudo apt update
$ sudo apt install certbot
$ sudo certbot --<YOUR_WEBSERVER>

Replace <YOUR_WEBSERVER> with the external web server you use. (apache, nginx, etc.)

Make sure to choose your domain/site and your preferred options during the installation. Wait for it to finish and SSL should be set up.