Playing with Debian

Saturday, 1st March 2008 at 12:30am

Name-based virtual host from your VPS, thanks to Apache

My situation: I was running www.allroundnews.co.uk fine on my shared host server, SH5 (thanks BEA Solutions ^^). Then I decided to switch to my VPS, Trinity, to run this blog. This blog is run from Trinity, but the rest of *.allroundnews.co.uk is still run from SH5. I realised that I was using up valuable space and bandwidth on SH5, when I had tonnes of both on Trinity. That's when I decided to run a virtual host for both of them. Here's how.

First, we have to fix the default Apache2 configuration, which isn't quite ready for vhosts yet. As root, edit the file /etc/apache2/sites-availiable/default. At the moment, mine and yours, if you haven't edited, looks like this, (well, I've changed the ServerAdmin, but that's about it.) We need to add the server name directive. That's just the URL that you want this vhost to be found at. I just had to add:

ServerName trinity.allroundnews.co.uk

That's fixed that. Since I'm running Trinity from a subdomain, that's all I need to add, but if you're expecting users to be able to use the www. prefix for your website, then you'll need to add a ServerAlias. If you're website is debianisawesome.com, you'd have something like the following:

ServerName debianisawesome.com

ServerAlias www.debianisawesome.com

Now that's fixed, we need to set up another VirtualHost for us to be using. In it, you need at least the ServerName and DocumentRoot directives. Remember, the ServerName is the URL Apache is "listening" for. The DocumentRoot is where it gets its files from. Try make this different from your default one, else it'll just get confusing. Here's what I've added to mine:

<VirtualHost *>

        ServerName www.allroundnews.co.uk

        ServerAlias allroundnews.co.uk *.allroundnews.co.uk

        DocumentRoot /var/www-allroundnews/

</VirtualHost>

I went ahead and created /www-allroundnews/ too, and gave myself permissions.

My new config file can be found here.

All you need to do now is copy all your files from one server to your VPS. I did that by getting them all from SH5 using FTP, then uploading them all to Trinity using WinSCP. Any better way than that; comment, please!

Then, remember to point your old DNS records to your server, and you're good to go.

Comments

Your name: Your URL:

Body:

User comments

Ober says:

Log in on your server and FTP them straight over rather than downloading and uploading. Your server is probably quicker too. :)

shamess says:

I don't have an FTP server on Trinity at the moment, so I don't think I could do that, could I?

Ober says:

Well, since you only want to download stuff from SH5 to Trinity, you just need an FTP client. If you don't have one installed, then it's just an apt-get install away.

Andrew McKay says:

As Ober says, you have an ftp client installed on trinity so you could use that to login to SH5 and get them that way or...scp should be installed on SH5 so you could scp them (man scp for the command line options). Also, tar and gzip should be installed on SH5 and trinity so you could create a tarball so you only have one file to copy. (tar zcvf thing.tgz directoryname to create tarball of a directory and tar zxvf thing.tgz to untar it). That's what I'd do anyway :)

shamess says:

Thanks, Andrew! I'll look into that more. :)

Read some previous entries