Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 matt@example.com
        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 matt@example.com
        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?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
1  
The thing with this is it will foreward all traffic on the IP, so example.com:25565 will direct to the same thing as minecraft.example.com:25565, which I do not want, due to the fact that I may have server1.example.com -> 25465 server2.example.com -> 25365 –  Matt Clark Nov 25 '12 at 4:48

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 of minecraft.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. :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.