1 Dynmap with Nginx server on Centos
FedUpWith-Tech edited this page 2020-08-01 15:59:27 -04:00

Setting up Dynamic Map with Nginx under CentOS 6.X

Introduction

One of the ideas behind using Nginx (or Apache for that matter) instead of the built in "Jetty Web Server" is that you can alleviate some of the strain to bukkit that may occur due to high traffic etc. to the map. If you host your own website (and therefore are already using port 80), it will also allow you to have the map sitting on a nice http://map.example.com/ as opposed to http://map.example.com:8123/ (setting up DNS records is past the scope of this document).

Note: This guide is made with the assumption that the web server is seperate to the Minecraft server. In this example I will use 192.168.1.2 for the Minecraft server and 192.168.1.3 as the Nginx server. If you choose to run them on the same server you could just change the 192.168.1.2 to 127.0.0.1 in the configurations - just be aware that this is likely not an optimal configuaration (questionable if proxying in the situation would help?).

CentOS

Why CentOS? From Wikipedia: "CentOS is a free operating system distribution based upon the Linux kernel. It is derived entirely from the Red Hat Enterprise Linux (RHEL) distribution. CentOS exists to provide a free enterprise class computing platform"

For installation I normally use a 'minimal' install ISO and then install anything extra I may need. I prefer installing less and then adding anything missed rather than installing more than I need to begin with. Mirrors are Here. The x86_64 minimal ISO is located at '/6.X/isos/x86_64/CentOS-6.X-x86_64-minimal.iso' relative to the mirror (where the X is replaced by the most recent version - at time of writing - 6.4).

Install CentOS and remember to set up the network during the install otherwise when you first boot you'll have to manually edit '/etc/sysconfig/network-scripts/ifcfg-eth0' to configure the network. It is important that a static IP is set, though you can either set it here or on the DHCP server (normally the router). You may wish to configure SSHd at this point, but it is isn't required.

Install Nginx, PHP and PHP-FPM

Install nginx following the instructions Here. So if you installed x86_64 CentOS then you'll run the following commands (while logged in as root) rpm -ivh http://mirror.yandex.ru/epel/6/x86_64/epel-release-6-7.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

In the "Configuring Nginx" section, I personally used /var/www/map.example.com/public_html and /var/www/map.example.com/logs, but it is up to you.

Note: Also create a folder for the cache eg. /var/www/cache and run chown nginx:nginx /var/www/cache.

Set up the "site"

In the /etc/nginx/sites-available/map.example.com file you created, change it to the following:

    proxy_cache_path  /var/www/cache levels=1:2 keys_zone=map:8m max_size=1g inactive=24h;
server {
    server_name map.example.com;
    access_log /var/www/map.example.com/logs/access.log;
    error_log /var/www/map.example.com/logs/error.log;
    root /var/www/map.example.com/public_html;

    location / {
        proxy_pass                  http://[IP OF MINECRAFT SERVER]:9999/;
        proxy_set_header            Host $host;
        proxy_cache                 map;
        proxy_cache_key "$host$uri";
        proxy_cache_valid  200 302  60m;
        proxy_cache_valid  404      10m;
        proxy_cache_use_stale       error timeout invalid_header updating http_500 http_503 http_504;
        proxy_connect_timeout 10;
    }
}

Adjust the proxy_pass variable to point to the IP and PORT of the dynmap webserver

Finishing Off

Run the command: service nginx reload to reload the configuration.

Ensure that port 80 is open in the firewall (iptables) and that the public IP of the nginx server has a DNS A record assocaited with the map.example.com domain.

Browse to http://map.example.com