Providing subdomain routing by modifying /etc/hosts (how to do this on remote server?)

0

1

I am using a convoluted and badly documented piece of software (sfDomainRoutePlugin) to provide subdomain functionality for my website. I am using Apache as the web server, and running a headless Ubuntu 10.0.4 LTS on the server.

After much trial and error, I found that the only way I can get my generated subdomain links to work (without getting a 'Server Not Found' error), was to hardcode the subdomain names into my /etc/hosts file.

This works fine when I am testing on localhost - however, I want to deploy the solution to a remote server which is running several virtual servers (different websites). The remote server does not make use of the /etc/hosts file at all, as each website has a unique name.

My question is this: can I simply enter the hardcoded domain entries (along with the static IP address) in the etc/hosts file? or is there another way of doing this?

My proposed approach would be to modify the /etc/hosts file on the remote server as follows:

123.456.789.123    foo.example.com
123.456.789.123    foo1.example.com
123.456.789.123    foo2-bar.example.com

Where 123.456.789.123 is the static IP of the remote server.

Is this the way to do it?

I would be especially greatful to hear from anytone that has managed to use sfDomainRoutePlugin for a similar purpose, in a production environment.

Homunculus Reticulli

Posted 2011-10-01T11:45:49.617

Reputation: 213

Answers

2

If all subdomain must be served by one physical site, you have:

  • write in DNS-zone smth.like

    www IN A ip-address

    somename IN A another ip-address /if it needed/

    • IN CNAME www

last records will give you for all and any undefined in zone names IP of www as answer

  • In hosting control panel define *.domainname as alias for www site

can I simply enter the hardcoded domain entries (along with the static IP address) in the etc/hosts file?

No. With hosts you'll be able route requests to correct server, but it will not be able to process requests without knowing about subdomain mapping (these sites doesn't exist for server)

Lazy Badger

Posted 2011-10-01T11:45:49.617

Reputation: 3 557

I think you may be on the right track (see: http://oldforum.symfony-project.org/index.php/t/20571/ [message #80434]) - only problem is that I did not understand most of what you wrote, since I am not very familiar with web server sysadmin. Could you please explain what you wrote (perhaps referring to the link I provided, since the guy had the same problem?). Last, were your instructions for the Linode admin page? (I did not recognise most of what you wrote). My service provider is Linode - if that helps.

– Homunculus Reticulli – 2011-10-02T01:54:04.207

1

Since all of your domains/subdomains are using the same IP address, we do not need to worry about any reverse proxies. see below for some examples. These are for different domains but work just as well for the subdomains. You should not need to edit your hosts file.

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org

# Other directives here

</VirtualHost> 

Also, ping each one of your subdomains. If they do not return your static ip address then you know that it's a DNS/Record issue. You may need to look at the setup of your domain registration again or wait for the DNS (typically 15 minutes to an hour) to kick in.

kobaltz

Posted 2011-10-01T11:45:49.617

Reputation: 14 361

Thanks for your answer. I'm not sure if I did not phrase my question correctly, or if you misunderstood my question. Unless I am mistaken, your answer explains how to set up multiple virtual servers for one Apache instance. That is not the problem I have. I have already succesfully setup the virtual servers (each in a separate conf file - which I enable/disable using the a2ensite/a2dissite scripts). My problem relates to the fact that with one of the sites (www.example.com), I want to use subdomains (foo.example, foobar.example) for ONLY that site. I am using the sfDomainRoutePlugin. – Homunculus Reticulli – 2011-10-02T01:32:11.597

It sounds like you need to go to your website where you ordered your domain. The problem is most likely you're unable to forward the subdomains because those subdomains are not pointing to your IP Address. I know that most registrars have a wild card that you can set up so that *.example.com will point to w.x.y.z IP Address. So doesn't matter if you typed in foo.example.com or foobar.example.com because the wild card will be a catch all. – kobaltz – 2011-10-02T03:55:44.027