mydomain.com

The lifecycle of a web request

The Request

It all starts when a user requests a website via their browser (or something else)

The Request

  1. User enters the domain name for the website they want to visit.
  2. A conversion process occurs where the domain name "mydomain.com" is translated into an ip address.  This is usually handled by your ISP.
  3. Once the ip address is determined, the request is forwarded there.
  4. The server is listening for incoming connections, and responds with the requsted page
  5. The requested page is displayed in the browser.

Cool Visualization

http://goo.gl/C0lOEc

A Records or cname?

When dealing with setting up domains on a web server, you may have to configure these specific records on your host machine or domain registrar.

A record

Points a domain name to an ip address

cname

Points a domain at

another domain.

A Records are fastest, because once you look up the A Record, you know the ip address, CNAME's require multiple lookups before arriving at the proper A Record.

The role of apache

  • Apache does the job of serving the requested assets based on the details of the request
  • The request contains information like what domain name is being requested, and then determines if it knows about the requested domain name or file.
  • If it does, it serves up those files which are sent back to the browser.
  • The site / file appears on your browser and the request life cycle can begin again.
  •  

where do apache config files live?

/etc/apache2/

The main folder for apache configurations

/etc/apache2/sites-available

This folder holds the Virtualhost configs

/etc/apache2/sites-enabled

This folder holds the Virtualhost configs that are actually enabled by apache.

where do apache config files live?

/var/www

The main folder to put your site files if you're only hosting one site.

/etc/apache2/mods-available

This folder holds the configurations for the apache modules you might be running.

/etc/apache2/mods-enabled

This folder holds the links to the apache modules  that are actually enabled.

I made a change but nothing happend...

Apache is typically set to start up as soon as the server boots up.  If you make changes to an already running server, they won't be recognized until the server is restarted.  To do that simply run:

$ sudo service apache2 restart

Just remember, your web server will be unavailable during a restart, so it's best to run these operations at off-peak hours.

apache virtual host

  • Allows you to host multiple websites on one server.
  • Uses a series of directives that configure each site under Apache.
  • Also allows for configuring things like SSL certificates if your site content should be encrypted.

Sample virtualhost file

Click the

link

Fun with hosts file

A hosts file is used to direct a url you might enter into the browser to a specific domain name.  For instance, with vagrant you might use "localhost:8080", but wouldn't it be nice if you could use "myapp.dev:8080"?

On Linux:

/etc/hosts

On windows:

C:\Windows\System32\Drivers\etc\hosts

On Mac

sudo nano /private/etc/hosts

http://goo.gl/FlX0Q0 <- more info about hosts files

Fun with hosts file

Open the hosts file as an admin and you can edit the contents to add ip addresses for any url you want.  My hosts file by default looks like:

This is where you want to edit

Fun with hosts file

New hosts entry

Tab between the ip and the name

Now when you navigate to bbu.dev:8080 it will forward you on to 127.0.0.1, which is the same thing that localhost was doing previously.

Fun with hosts file

Finally, you need to setup a virtual host in apache that will accept "bbu.dev" as the server name (or alias).

 

This could be accomplished by simply adding:

ServerAlias bbu.dev

to your Virtualhost for your vagrant server which would be found in:

/etc/apache2/sites-available/000-default.conf

Made with Slides.com