Redirect non-HTTP traffic to a port, based on a su

2019-04-09 01:55发布

问题:

I'm working on making my two Minecraft servers easier to access. I've attempted a few solutions, but so far, none have worked effectively.

I have a normal vanilla Minecraft server listening on mysite.com:25560, and a Tekkit Minecraft server listening on mysite.com:25570. That is, both Minecraft servers are running on the same machine. They work properly when users directly connect to the server with the port specified.

The vanilla server was initially listening on mysite.com:25565, the standard Minecraft port. I have changed it so I can allow Apache to listen at mysite.com:25565 and redirect traffic appropriately, but that's not working so far.

What I'd like to be able to do is have all requests sent to mine.mysite.com be redirected to mysite.com:25560, and have all requests sent to tekkit.mysite.com be redirected to mysite.com:25570. I understand that the DNS itself is not capable of managing this reroute, since DNS only handles domain names and IP addresses.

After a suggestion of a friend, my latest attempt has been reconfiguring Apache, as I earlier stated, to listen on port 25565 and proxy the traffic to the correct port. This is a section of my apache2.conf:

Listen 25565

NameVirtualHost *:25565

<VirtualHost *:25565>
    ServerName tekkit.mysite.com
    ServerAlias www.mysite.com
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPreservehost On
#   ProxyPass / www.mysite.com:25570/
    ProxyPassReverse / mysite.com:25570/
</VirtualHost>

<VirtualHost *:25565>
    ServerName mine.mysite.com
    ServerAlias www.mysite.com
    ProxyPreserveHost On
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
#   ProxyPass / mysite.com:25560/
    ProxyPassReverse / mysite.com:25560/
</VirtualHost>

The commented-out lines with ProxyPass cause Apache to start with an error ProxyPass URL must be absolute!

To see if I could make it work properly, I then tried substituting http://www.mysite.com:25560/60 in the respective places, and while Apache does start without any errors, users are not able to connect to the server. I believe this is because the Minecraft server does not redirect a HTTP request to a server connection, whichever protocol that may be.

This has led me to believe that Apache won't be helpful in handling non-HTTP requests. If I am mistaken, how might I make Apache correctly redirect subdomain traffic to a port? Otherwise, can anyone suggest a way to do this without Apache? I have access to all standard Linux / Ubuntu utilities. I've been searching for quite some time without progress.

Thanks!

回答1:

Solution 1:

I don't think this is going to work with Apache, as you can only get errors. After searching for a while on the internet I found the following: https://github.com/SirCmpwn/MCVHost. I'm not sure if it works, but if it does it perfectly suits your needs I think.

If you are on Linux you can probably run it with Mono, as I've not found any Java or Python equivalent.

Edit: I just tested it and it doesn't work with 1.4.6 because the protocol changed

Solution 2 (and probably the best):

Use SRV records, which Minecraft recognizes since 1.3. A manual has been published by Multiplay at http://wiki.multiplay.co.uk/Minecraft/Hostnames.



回答2:

I believe iptables will do this for you, assuming you're on Linux:

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 25565 -j REDIRECT --to-port 25560

You have to be root to run this command, and it is not permanent. You will have to run this every time the server restarts.