Aug 10, 2012

How to serve multiple domains


How to serve multiple domains
Most people serve more than one domain on their Slice(s).
Whether for different domain names or different subdomains of the same domain, the procedure is the same.

Question
I am often asked by people how to use their Slice to serve multiple domains.
The question often surprises me as they may have setup their Slice, installed a web server (Apache, Nginx, etc) and even created a virtual host to serve their main domain.
Don't get me wrong, the question itself is good (I like questions as it makes me feel useful!), but the answer is always so simple:
Create another vhost.
Outline
There may not be a great deal I can add to the answer but let me outline the process of setting up a Slice and creating a virtual host (I won't go into any details of the installation and creation process - please see the relevant articles for detailed help).
When your Slice is first created it is a minimal Linux install (it doesn't matter what OS you choose).
You SSH into the Slice and update and secure it.
Then you install your preferred web server (Apache, Nginx, Litespeed, etc).
Then the detailed stuff begins. It doesn't matter if your site is PHP based or Rails based or something else entirely. You install the language and framework basics (say Ruby and rubygems or mod_php and so on).
Once that is all done, you come to the part that allows you to server your site: creating virtual hosts.
Procedure
Greatly simplified the procedure for serving a website is as follows:
A browser send a request to your Slice IP asking for the contents of 'domain.com' (your domain name).
Your web server jumps into action and says 'yes! I have something for you'. The web server does its 'thing' and serves up an http representation of your site which is sent to the browser.
The browser then translates the http and parses it to a human form of the web site (something like this one).
All jolly good but how does your web server know what to send?
Virtual Hosts
This is where name based virtual hosts come in.
One of the first lines in any virtual host contains the domain name that is related to the vhost.
Something like this for Apache:

  ServerName  domain1.com
  ServerAlias www.domain1.com
and something like this for Nginx:
server {

  server_name  www.domain1.com;
  rewrite ^/(.*) http://domain1.com/$1 permanent;
Each one starts slightly differently but the same principle applies - that particular virtual host will respond to queries for 'domain1.com' and 'www.domain1.com'.
Multiple domains
So, to serve different content for different domains is as simple as adding another virtual host.
Let's say you have a subdomain called 'blog.domain1.com' serving a blog (I know, shocking originality!).
The basic creation process would be to create a folder in your public_html folder with the relevant files (let's say a Wordpress install).
A virtual host would be created with the server_name or ServerName as 'blog.domain1.com' which would be configured to point to the blog files and folders in your public_html folder.
Done.
Language and frameworks
It doesn't matter what language or framework your domain uses.
To serve multiple Rails applications for example requires the same setup for each application.
Of course, there would be some differences such as port numbers for the mongrel or thin instances. Virtual hosts can't share ports.
For example, you may create a mongrel cluster to run from port 8000 - 8002 for one domain and another running from 8010 - 8012 for your blog and so on.

Mar 20, 2012

How to Delete in Linux Terminal rm Command ?

Many Linux users get confused when they are in a Linux terminal and trying to delete files of folders. So in this Linux tutorial, I will cover how to delete files in Linux terminal! The Linux delete command is another basic command that is used everyday while in a Linux terminal. There are only 2 options that I use on a regular basis with the Linux rm command.
The usage of the Linux rm command is rm [options] [file|dir]. The 2 options I use most is rm -r [dir] and rm -f [file]. Now to explain these options for the Linux delete command and also give you some examples on how to remove a file with Linux.
The rm -f [file] option is if you are wanting to force a file to be removed. This will not ask you “are you sure you want to remove [file]“. It will just delete the file regardless. So use this option for the Linux rm command only if you know you want all of the file(s) deleted.
Now the rm -r [dir] option is if you are wanting to delete a directory in Linux. The rm -r option is to specify to remove recursively, meaning a directory and it’s contents.
You can use these 2 options for the Linux delete command together as well. You could use the command rm -rf [dir] to delete a directory forcefully and recursively. DO NOT be fooled into running rm -rf /, rm -rf /* as this will remove all of your files and folders. Some people may come off as they are trying to help you with Linux and be a dick and tell you to run rm -rf /* which you can then say bye bye to your files and folders.
You can also use rm in a script type command after a pipe | so you can delete filenames of the output. You can also use rm to remove files that are produced from another command or script. Here is an example of how to remove a file found after grep in Linux. Say if you have a folder /home/max/images/family and in this directory you have 20 images that have the word copy in the title because you accidentally highlighted these 20 files, went to drag them into another folder in a GUI, and let go too early and created copies. So now you want to remove these copies, you would first cd to that directory cd /home/max/images/family now you can run rm -f `ls |grep copy` which will remove all the files that ls | grep copymatches. This same process could be done easier by running rm -f *copy* instead, but these are just examples.
I hope reading this Linux tutorial on the Linux rm command has taught you more than you already know and that you can continue reading through this Beginner Linux Tutorial website and learn even more about the Linux operating system! Have a great day and rememberDO NOT run rm -rf /* or any variation of it. I will write a section on Beginner Linux Tutorial explaining more of the commands that can harm your system to watch out for when people are trying to help you with Linux so that you will not be a victim of this. If you are unsure if a command will harm your system, you can always do a quick reference check by searching the net for that command, or even looking at the man pages for that command to see what it is that command/options will do. You can read your manpages by typing man [command] like man rm will bring up the manual for the Linux rmcommand.

Feb 24, 2012

How to edit in sudoers command ?

Sudoers are those whom delegate some admin tasks to the normal user. How to add a user to the sudoers list? Believe it or not, this is a fairly common question and in all reality the answer is quite simple. Adding a user to the sudoers list on a fully installed Linux system such as Debian is only possible via the command visudo. Users in the sudoers list are allowed the privileges to run commands and open files as the root user. In the following quick tutorial, we will show you how adding a new sudoer is quickly done.
How to add a user to the sudoers list:
1. Open a Root Terminal and type visudo (to access and edit the list)
2. Using the up/down arrows, navigate to the bottom of the sudoers file that is now displayed in the terminal
3. Just under the line that looks like the following:
root ALL=(ALL) ALL 
4. Add the following (replacing user with your actual username)
sir ALL=(ALL) 
5. Now press Ctrl+X and press Y when promted to save
That's it, your new user now has root privileges!
Example Sudoers Screenshot: