Minecraft web server

Minecraft May 24, 2020

So I recently set up my minecraft server after a very long hiatus; with the shelter in place not ending any time soon, the conditions are surely perfect to get back into this :)

Some things seem to have changed since 2015 or whenever I last properly played Minecraft. My previous setup involved the FTB launcher and the Yogcraft modpack, which included a bunch of silliness including ComputerCraft, BuildCraft and IndustrialCraft. Here's a nugget I found from that time:

You said something about a web server?

Yeah, so I have a bee in my bonnet - I want a 'webserver' in minecraft-land that I can access from the outside world. For no particular reason beyond figuring out if it's reliably doable and what kind of "horrible stuff" is required to make it happen.

Parts

I'm using the FTB Revelation modpack because frankly, it was the first one on the FTB launcher and Yogcraft isn't there anymore. I'm also going to be using creative mode and start with a file in a computer that can be served statically. I remember that computer files used to live in a directory that could be read from outside minecraft; hopefully this is still the case, as it will probably make this a whole lot easier. Here it is:

I made a new file with some known content; let's have a poke around the minecraft server directory and try to find it...

lmarshall@tuvok:~/minecraft/world/computer$ tree
.
├── 0
│   └── myfile.txt
└── lastid.txt

1 directory, 2 files
lmarshall@tuvok:~/minecraft/world/computer$ cat 0/myfile.txt 
TESTFILE

Well that was easy! Guess this is going to be a short one :)

Lets set up nginx

lmarshall@tuvok:~/minecraft/world/computer$ apt install nginx
...
lmarshall@tuvok:~/minecraft/world/computer$ sudo nano /etc/nginx/sites-enabled/default
Install nginx and configure it
server { 
        listen 80;
        listen [::]:80;

        server_name mc.routevegetable.com;

        root /home/lmarshall/minecraft/world/computer/0/www;
        index index.html;

        location / {
                try_files $uri $uri/ =404;
        }
}
Virtual host configuration for 'mc.routevegetable.com'
Added the port forwarding for nginx to my router

Annoyingly, I get the router configuration page when I now try to go to http://mc.routevegetable.com in my browser - looks like my router is trying to be helpful. Hmm; gonna have a quick look around for a switch that controls that in the router config...

Ah-hah! I can add a DNS record for my LAN only:

Now a re-connection later to flush my local DNS cache and...

So, there are a couple of things that are unsatisfying about this:

  • We hardcoded the path /home/lmarshall/minecraft/world/computer/0/www into the nginx config, meaning that this specific computer is now special, and we can't make another web server without messing with the nginx config.
  • It would be pretty awesome to be able to get some real interaction going, so you can trigger programs you write in minecraft. Like a CGI bin, but sandboxed within minecraft.

I think that's enough silliness for this morning.

Tags