Sub Domain address forwarding to a different IP and port

Hi all,

Have installed Virtualmin a few days ago whilst trying out web hosting S/W like ZpanelX and ISPConfig. It’s by far the most comprehensive however I have my own question to which I couldn’t find an answer to.

Here is the scenario:

One domain hosted with GoDaddy which points to the name servers here at my office. At the office I have setup Virtualmin behind a firewall and port 80 is open as well as several other ports which point to systems on VMware machines that run standalone applications such as wikis and software project management tools.

I can access the main domain ( and have created several other sub domains so for example has and which should be pointing to a different IP and port but somehow they don’t. I have gone in manually and changed the IP in Server Configuration > Change IP Address to point to the correct server and port. The result is that it can’t connect to the page requested.

How can I get the sub domains working without having to manually type the port in the IP address?

Let me know if I need to clarify things more.



Is your server using NAT, and have internal IP addresses setup on it? Or does it have public IP addresses?

Also, if you go into System Settings -> Re-Check Config, does it notice any problems?


In addition to what Eric asked:

You cannot point subdomains to ports, except for http redirects. It depends on what software exactly you are running on those subdomains. You named wiki and project management tools. Are those web applications, with an Apache or similar serving them?

If so, it indeed depends on whether you have one or multiple public IPs for your box(es). If it’s multiple, you can point the subdomains to the correct one at GoDaddy. If not, you need to point them all to your one external IP, and since DNS doesn’t know port numbers (except for SRV records, which http doesn’t use), you’ll have to make Apache redirects or reverse-proxy which CAN include port numbers. Or, you could type in the port number in your browser request.

It all depends on your exact network layout, of which you should tell us more. :slight_smile:

Hi Eric,

Thank you for coming back to me. The server is setup with internal IP addresses that resolve to individual ports. The main domain resolves to port 80.

Went to system information and saw that the apache service needed restarting, when I tried restarting, it said:
Failed to start service :

  • Starting web server apache2
    [Fri Dec 07 23:39:20 2012] [warn] NameVirtualHost has no VirtualHosts
    (99)Cannot assign requested address: make_sock: could not bind to address 10.0.0.xxy:8080
    no listening sockets available, shutting down
    Unable to open logs
    Action ‘start’ failed.
    The Apache error log may have more information.

These are the last two lines from the apache log:
[Fri Dec 07 13:54:37 2012] [error] proxy: ap_get_scoreboard_lb(0) failed in child 26024 for worker proxy:reverse
[Fri Dec 07 13:55:08 2012] [notice] Graceful restart requested, doing restart

and then its the text above.

The NameVirtualHost should be 80 and not 8080, but I’m not sure where its picking it up from so that I can change that, also the bind to address 10.0.0.xxy:8080 is where one of the stand alone VM’s is and the port on the gateway is open so in theory it should bind to it.

Any suggestions would be very welcome as now I don’t have any sites up.


This is getting a bit complicated without precisely knowing what your network setup looks like and what kind of layout/forwarding you’re trying to achieve , so just some general hints from me:

The error from Apache means that it’s trying to bind to port 8080, but cannot, because some other process is already listening on that port. You can find out which with the command netstat -tpln | grep 8080.

I don’t understand what you mean with “set up with IP addresses that resolve to individual ports”. IP addresses have nothing to do with ports.

Having “ports open on the gateway” (I suppose you mean you have a port forwarding in place on your router?) has nothing to do with whether a daemon can bind to that port. That only depends on whether the port is already used by another daemon.

The port number used in your VirtualHost directive should come from Virtualmin’s server template, section “Apache Website”.

Hi Locutus,

Thanx for coming back to me.
Have since re-installed Virtualmin and have managed to configure correctly the main domain.

I don’t have multiple domains, I have one domain pointing from Godaddy to my static IP here at the office.
The wiki and the other apps are indeed web apps running from VM’s with Apache etc. They can be accessed by typing the external IP plus port but that is not an elegant solution for my users.
Ideally, I would like to type and be directed to and I think I found an answer you gave to another user back in 2010, - however as I don’t want to screw things up, can you be a bit more specific on how to do that i.e do I go in to:

Servers > Apache Webserver > etc etc.

Thanx again.


Ah, yes that’s right, for that purpose you can use either Apache’s mod_rewrite, or use reverse proxying.

In the first case, Apache will tell the browser when it wants “” to instead fetch “”. That will be reflected in the browser’s URL box too, so if that’s not an issue, you can do that.

The example you quoted from my earlier post should do fine. Additionally, since you’re not rewriting to a different domain, you’ll probably need some Condition to only rewrite if the port number is 80 or not given. Otherwise you’ll end up with an endless rewrite loop, since the rewrite matches the rewritten address too. I’ll look up the proper syntax in a bit.

For reverse proxying, you’ll have your Apache on port 80 make a HTTP connection to the actual service the user wants, forward the request, and forward the result back to the user. The advantage is that the user doesn’t see the modified URL in the browser bar, the disadvantage is a more complicated setup and the target service sees all connects as coming from your primary Apache.

Try to add this to your vhost config (via “Services / Configure Website / Edit Directives”). Make sure to not duplicate any existing directives like RewriteEngine.

ServerAlias RewriteEngine on RewriteCond %{HTTP_HOST} RewriteCond %{SERVER_PORT} !^port RewriteRule ^(.*) h-t-t-p:// [R]

Replace “port” with the port number, and “h-t-t-p” with “http”.

Alternatively, you could make the rewrite target without the “subdomain”. If it’s a web service on a different virtual machine anyway, it doesn’t really matter if it gets called by a subdomain name that maps to the same IP anyway. If you leave out the subdomain in the rewrite rule, you don’t need the SERVER_PORT RewriteCond.

In the end it was simpler than simple.
In the server configuration > Website Redirects create a new redirect with the url path essentially being a forward slash to indicate the base of the url and then putting in the destination which in my case was the url + port.

Worked like a treat.

Thanx all for your replies.