Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Internal vs External Web Server

BillyGalbreath edited this page Sep 20, 2022 · 2 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. You can set it 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.

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

1 - Set up a server directory for Pl3xMap

This is the directory the web server will serve the map from.

$ sudo mkdir -p /var/www/YOUR_DOMAIN

Replace YOUR_DOMAIN with the domain you wish to use. This can be the name of a subdomain.


2 - Assign the correct permissions to the server directory

This will allow your user to read/write to the directory.

# assign ownership to the user
$ sudo chown -R $USER:$USER /var/www/YOUR_DOMAIN

# gives the owner read/write/execute perms and only read/execute perms to other users/groups
$ sudo chmod -R 755 /var/www/YOUR_DOMAIN

3 - Move the files from the default Pl3xMap web directory (plugins/Pl3xMap/web) to the web server's web root directory (/var/www/YOUR_DOMAIN)

This can be done in one of two ways:

Creating a symlink from the Pl3xMap web directory:
$ sudo ln -s /path/to/your/server/plugins/Pl3xMap/web /var/www/YOUR_DOMAIN

As usual, replace YOUR_DOMAIN with your domain, and /path/to/your/server/ to the path where you run the server.

Updating the path in Pl3xMap's config is not required if using a symlink. Instead, your server block configuration will require additional options.

Copying the web directory to the web server's root directory:
$ sudo cp /path/to/your/server/plugins/Pl3xMap/web /var/www/YOUR_DOMAIN

As usual, replace YOUR_DOMAIN with your domain, and /path/to/your/server/ to the path where you run the server.

Now that you moved the web directory to /var/www/YOUR_DOMAIN, you need to update the path in Pl3xMap's config.


4 - Configure your web server

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 without a reverse proxy.

This section assumes that you have:

1 - Setting up the NGINX site

$ sudo nano /etc/nginx/sites-available/YOUR_DOMAIN

This will create a new file under /etc/nginx/sites-available. Paste the snippet below:

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

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

  server_name YOUR_DOMAIN; # the name (domain) of the server

  location / { # location of your files
    try_files $uri $uri/ =404; # if location == null return 404
  }
}

This will create a new site config for Pl3xMap. As usual, replace YOUR_DOMAIN with your domain.
After you're done editing the file, save and exit with Ctrl + X.


2 - Activating the site

This command will symlink our new site file with one in /etc/ngnix/sites-enabled/:

$ sudo ln -s /etc/nginx/sites-available/YOUR_DOMAIN /etc/nginx/sites-enabled/

This is the directory where NGINX will read enabled sites.

To avoid a possible hash bucket memory problem that can arise from adding additional server names, it is necessary to adjust a single value in the /etc/nginx/nginx.conf file:

...
http {
  server_names_hash_bucket_size 64; # uncomment this option
  ...
}
...

This option controls server names. You can learn more here.


3 - Test and restart NGINX

Run this command to check your NGINX config for syntax errors and misconfigurations.

$ sudo nginx -t

If there were no errors, restart NGINX with this command:

$ sudo systemctl restart nginx

Start your Minecraft server and make sure nothing appears in /path/to/your/server/plugins/Pl3xMap/web.

Navigating to http://YOUR_DOMAIN/ should show you the map.

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 caddyile.

Add this snippet to your caddyfile:

<YOUR_DOMAIN>
root * <file_location> # location of your Pl3xmap files `/server_root/plugins/Pl3xMap/web` by default
file_server
@gz {
	path *.gz
}
handle @gz {
	header Content-Encoding gzip
}

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

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 is 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.

This section assumes that you have:

1 - Setting up the NGINX site

$ sudo nano /etc/nginx/sites-available/YOUR_DOMAIN

This will create a new file under /etc/nginx/sites-available. Paste the snippet below:

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. Replace YOUR_DOMAIN with your domain, MAP_IP with the IP hosting your Pl3xMap instance, and MAP_PORT with the port Pl3xMap is hosted on.
After you're done editing the file, save and exit with Ctrl + X.


2 - Activating the site

This command will symlink our new site file with one in /etc/ngnix/sites-enabled/:

$ sudo ln -s /etc/nginx/sites-available/YOUR_DOMAIN /etc/nginx/sites-enabled/

This is the directory where NGINX will read enabled sites.

To avoid a possible hash bucket memory problem that can arise from adding additional server names, it is necessary to adjust a single value in the /etc/nginx/nginx.conf file:

...
http {
    ...
    server_names_hash_bucket_size 64; # uncomment this option
    ...
}
...

This option controls server names. You can learn more here.


3 - Test and restart NGINX

This command will check for syntax errors and misconfigurations:

$ sudo nginx -t

If there were no errors, restart NGINX with this command:

$ sudo systemctl restart nginx

Start your Minecraft server and make sure Pl3xMap's internal server is running.

Navigating to http://YOUR_DOMAIN/ should 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 caddyile.

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 <something> with your own values.

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.
You can get a free SSL certificate by running the commands below:

$ sudo apt update
$ sudo apt install certbot
$ sudo cerbot --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.

Clone this wiki locally