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.

Right now I have a server running on IP:Port. If I wanted to use DNS but redirect to the port, how would I do so? I've heard that it's possible, but how would I do so, even if it includes creating something such as a proxy?

For example, visiting:

domain.tld

would instead access

IP:Port

and the port could be anything I wanted it to be.

If no direct solution exist, how would I go along using a "VirtualHost"?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You could do this with Apache, or almost any other webserver, and in brief you'd configure your server to do two things:

  • Listen on :80 to accept the initial request.
  • When you so a request for example.com you'd then redirect to the alternative location. e.g. 1.2.3.4:82

However you will probably find visitors from large corporations, behind firewalls, will be unable to view your site. (Because their outgoing firewall might allow connections to the standard ports 80 + 443 but not others. So they'd redirect to a location they couldn't view.)

In short unless you have a fine reason for doing this then it is almost certainly a bad plan. (You don't can run an arbitrary number of sites on one webserver, each on port 80. If you need to run multiple SSL sites you will need extra IPs though, traditionally.)

Here's a brief example:

 NameVirtualHost 1.2.3.4:80

 <VirtualHost 1.2.3.4:80>
    ServerName example.com
    ServerAlias www.example.com
    Redirect 301 / http://3.4.5.6:83/
 </VirtualHost>

 <VirtualHost 1.2.3.4:80>
    ServerName example.net
    ServerAlias www.example.net
    Redirect 301 / http://3.4.5.6:82/
 </VirtualHost>

 <VirtualHost 1.2.3.4:80>
    ServerName example.org
    ServerAlias www.example.org
    Redirect 301 / http://3.4.5.6:2020/
 </VirtualHost>
share|improve this answer
    
How would I go about doing this If I wished to redirect something that's not http or https? –  hexacyanide May 30 '12 at 16:49
    
If you redirect to something that is not HTTP/HTTPs (albeit on a non-standard port) then the browser making the request is going to get confused .. so the question you're asking doesn't make a lot of sense! –  Steve Kemp May 30 '12 at 16:54
2  
@hexacyanide - Two points: 1) http and https are protocols. They happen to typically run on 80/443 respectively, but there's nothing preventing you from running them anywhere you'd like. 2) Running these protocols on anything but their standard ports will be very problematic. Sure, it's fine to do that for development, but for production, you need to stick with 80 and 443. –  EEAA May 30 '12 at 17:07

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.