I am trying to setup my server with a Minecraft server on a non-standard port with a subdomain redirect, which when navigated to by minecraft will go to its correct port, or if navigated to by a web browser will show a web-page. i.e.:
**Minecraft**
minecraft.example.com:25565 -> example.com:25465
**Web Browser**
minecraft.example.com:80 -> Displays HTML Page
I am attempting to do this by using the following VirtualHosts in Apache:
Listen 25565
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName minecraft.example.com
DocumentRoot /var/www/example.com/minecraft
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/example.com/minecraft/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:25565>
ServerAdmin [email protected]
ServerName minecraft.example.com
ProxyPass / http://localhost:25465 retry=1 acquire=3000 timeout=6$
ProxyPassReverse / http://localhost:25465
</VirtualHost>
Running this configuration when I browse to minecraft.example.com I am able to see the files in the /var/www/example.com/minecraft/ folder, however if I try and connect in minecraft I get an exception, and in the browser I get a page with the following information:
minecraft.example.com:25565 ->
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /.
Reason: Error reading from remote server
Could anybody share some insight on what I may be doing wrong and what the best possible solution would be to fix this?
The Minecraft server protocol isn't HTTP so you can't proxy the requests like that.
Assuming you're on Linux, use iptables to forward the TCP port. You can still run Apache on port 80 on the same IP, but remove the Listen directive and respective vhost in your config there.
IPTables rule should look something like:
iptables -t nat -A PREROUTING -p tcp -d --dport 25565 -j DNAT --to 127.0.0.1:25465
Remember to actually allow the traffic with an entry in the INPUT/OUTPUT chain too of course.
iptables -t nat -A PREROUTING -p tcp -d 12.13.14.15 --dport 25565 -j DNAT --to 127.0.0.1:25465
Where
12.13.14.15
is the IP address ofminecraft.example.com
.NOTE THAT YOU CANNOT USE VIRTUAL HOSTING FOR THIS. If you wanted to host server1.example.com and minecraft.example.com on the same public IP, both to do this kind of port-level redirection... sorry, ain't gonna happen. This stuff happens before the HTTP layer, so virtual hosting is irrelevant to it. :)