Serve local web pages via name not IP number

29.11.2008

Name your server

The first thing you need to do is come up with the name you'd like to use for your server--keep it short and simple, and restrict it to one word without any punctuation. The whole idea is to make it easy to type. For this example, I'm assuming the server will be called mysites, which would let you type http://mysites into your browser's URL bar.

Once you've come up with a name for your server, you need to tell OS X to look for that name locally before it tries to find it on the Internet. To do this, we'll make a simple change in the /etc/hosts file. My instructions assume you'll be using a Terminal-based text editor, such as vi or nano, but programs wuch as BBEdit and that offer a command-line interface could also be used--really, any text editor that lets you edit with root account privileges would do the trick.

Edit the hosts file in Terminal by typing sudo nano /etc/hosts, and then enter your password when prompted. The nano editor will open, displaying something like this:

Add a row just above the 255.255... line by pressing Return with the cursor at the start of that line, then use the arrow keys to move up, and add this entry: