Friday, April 6, 2012

Getting started with a Web Server


This week I am going to talk about creating a web server. A web server is used to host a number of services normally associated with web site building and web applications. A web server can be used to host Static Websites, such as a website about a small shop. Web Servers can also be used to host very large enterprise online applications such as eBay or a large online casino. Most probably, web sites with large online applications will have a front end on a web server, and having separate application and database servers.

Simple Web Server Installation using XAMPP for Windows

XAMPP is a small application which is mainly used for testing environment. It is not suggested to use XAMPP in production because it uses a package of services, some of which you might not need, posing more security risks in your web server. When setting up a production server, it is best to install the required services only when needed.

The XAMPP installation includes Apache, Perl, PHP, FileZilla, J2EE, MySQL, SMTP and Tomcat. All of these services are installed by default when installing XAMPP from the simple installer. To install XAMPP, is it fairly simple as it requires no knowledge of these technologies. It is just an installer and by pressing Next, Next, Next.... you can end up with a working web server. By default, each one of the services has to be started manually using the control panel of XAMPP, but there is also the option of starting them as a Windows Service, especially if the services are constantly used for testing purposes.

XAMPP also has a control panel which can be used to start and stop services. This can also be very useful to monitor which services are running

Installation of XAMPP

Like I already said, XAMPP is very easy to install. The first option is shown in the picture below. The service section is very important. You might use XAMPP very little on your computer. If this is the case, you would prefer not to start all these services when your computer starts but prefer to start them manually when you need them. Then just press the install button to continue with the installation. When the installation is finished, the XAMPP Control Panel window pops up. This can be used to start and stop the services manually, to install the services to start with Windows and you can also view the status of each service. After, the installation, is it better to restart the computer running XAMPP.


Figure 1: The only option in the installation of XAMPP


Figure 2: The XAMPP Control Panel

The scope of this blog is to create the web server. The rest of the services, except for PHP will not be taken into consideration.

Testing Apache Installation

Now we need to test the installation of Apache. The web pages are stored in a folder called htdocs within the installation of XAMPP. The default location is C:\xampp\htdocs. To test the web server, we can create a simple html file called index.html and put it in the htdocs folder.

01
<html>
02
<head>
03
<title>Test Page</title>
04
</head>
05
<body>
06
<h1>It Works!</h1>
07
</body>
08
</html>


There are several ways to test if the server is working. This is done by typing specific keywords in the address bar of the browser. The following is a list of different methods to test the web server:
  • http://localhost/index.html
  • http://127.0.0.1/index.html
  • http://<<ip address>>/index.html
  • http://<<ip address>>/index.html (from another PC in the same network)
  • http://<<public ip address>>/index.html (from another PC on the internet)




Figure 3: Testing the Web Server with localhost


Figure 4: Testing the Web Server with localhost IP Address


Figure 5: Testing the Web Server with its IP Address from another computer

Another thing to test for is HTTPS. This is very important as it uses SSL to provide encrypted communication and secure identification of a web server. Most people are using this as a safer way to browse the web. By default, this service is enabled on the Apache installation. To test for this, we just need to replace http with https in the address bar.


Figure 6: Testing the Web Server with HTTPS but it presented an error

When using https, the browser issued an error message that the certificate is not trusted. Then it gave us the option to proceed anyway to the website, with the risk of exposing our computer to a security treat or else we can close the website before it is too late. But why is there this message?

HTTPS

When using https, the web server administrator must create a public key certificate for the web server. This must be signed by a trusted certificate authority so that the web browser can accept it without presenting such a warning. Such a certificate certifies that the certificate holder is the owner of the web server. Certificates can be acquired from any certificate authority and some organizations can have their own certificate authority.


Figure 7: We clicked on proceed anyway to view the content

PHP

PHP, a server-side HTML embedded scripting language, is also a part of the XAMPP. To test if PHP is successfully installed, we can create a small test document with phpinfo() function to display the configuration of the PHP instance. Then we can open the test file we created in a browser as shown below:


Figure 8: phpinfo() function showing the current installation of PHP

Private Web Server

Using XAMPP we created a web server on our computer. This means that the websites which we put on our computer are only accessible from our computer. To make our web server accessible on the local network, we need to create an exception in the windows firewall for port 80 and port 443 connection. This allows other computers to connect to our web server making our web server able to serve the local network.

Public Web Server

However this does not mean that people from outside our network can access our web server. Creating a public web server needs a little bit more configuration. First of all people need to know our public IP address. We can know this by using www.whatismyip.org. The return address will be the public IP address of our router.

Our internet providers need to supply our router with an IP Address. Depending on how much we pay for our internet service, we can either have a dynamic IP address or a static IP address. A static IP address, as its name implies is static and does not change by time. This is a requirement if we plan to host services such as mail and web servers. A dynamic IP address is subject to change over time and this means that if it changes, the web server will not be accessible anymore.

Then we need to configure the router to forward the traffic destined for ports 80 and 443 to our computer. This depends on the make and model of the router or firewall so I won't go into much detail here. If not done properly, however, this can expose some of the private resources to the general public.

DMZ

DMZ stands for Demilitarized Zone. This is a zone within our private network where our servers are placed. This is a security measure to ensure that our private network is safe from intrusions. A web server is normally placed inside this DMZ. The best example is when the network has two firewalls and the DMZ is enclosed between the two firewalls. An example can be seen below.


Figure 9: The most secure way to implement DMZ

The figure above shows a DMZ within two firewalls. The first firewall controls all the traffic from the External Internet the DMZ. External traffic is not allowed if not explicitly allowed by a certain rule on the firewall, such as to allow traffic on ports 80 and 443 to the web server. All other traffic that tries to access the internal network or DMZ is dropped. Also, traffic originating from the DMZ area is not allowed to enter the private LAN. This means that if the security of the Web Server is compromised, it does not automatically breach the internal LAN.

Go on and try to build your own web server now! I will be with you next week with more on PHP.

Sunday, April 1, 2012

Client Server Architecture


The internet revolves around to concept of a client-server architecture. What this means is that someone (a client) is requesting information from another person (a server). There are however no rules in defining exactly if a particular machine is only a server or only a client. A testing workstation can have a running instance of a server for example while being also a client. Here we will talk mostly about the WWW client server architecture.

To view websites and web services, an internet user makes use of a browser. The browser is the client side of the architecture. There are a lot of browsers such as Internet Explorer, Google Chrome, Mozilla Firefox and more. These browsers use a set of predefined protocols to connect to web servers anywhere in the world. Web servers can be running on the same machine for testing purposes, in the same office, and also on the other side of the world. The location of the server does not really matter. The only must have there is is that there is internet connectivity between the two. Below we can see a normal 2 Tier Architecture where a browsers makes a request to a Web Server. This is normally the case when accessing a simple static website.

Figure 1: Simple Two Tier Architecture – a Browser and a Server

Below we can see a 3 Tier Architecture. This is the case when we access a large system like for example a large online shop such as www.amazon.com.
Figure 2: 3 Tier Architecture – a Browser, an Application Server and a Database Server

Protocols

Browsers use a set of predefined commands to communication with servers. These are known as protocols. These protocols ensure that the data that needs to be transferred is transferred accurately and also securely. Not all protocols include embedded security features, but most protocols have a substitute including security measures and encryption such as HTTPS for HTTP. Several protocols are used in the client server architecture. These include HTTP, HTTPS, FTP, SFTP, SMTP, POP3, IMAP, SSH, Telnet and many more. HTTP and HTTPS, are Hyper Text Transfer Protocols, the later based on SSL for security, and are used to transfer text and images from the web server to the client browser. FTP and SFTP are File Transfer Protocols and are used to transfer files from a client to a server or vice versa. SFTP uses SSH. SMTP, Simple Mail Transfer Protocol is used to send emails. POP3, Post Office Protocol, and IMAP, Internet Message Access Protocol, are used to receive emails. SSH, Secure Shell and Telnet are used to connect to devices without a user interface. 

Transport Layer

In networking, Transport Layer (OSI Layer 4), provides end-to-end communication service for application. The two mostly used common transport protocols are TCP and UDP. TCP stands for Transmission Control Protocol while UDP stands for User Datagram Protocol. Two other protocols are available DCCP (Data Congestion Control Protocol) and SCTP (Stream Control Transmission Protocol). However, the latter two are not commonly used. TCP provides a secure way of transferring data. It uses a connection oriented mechanism that splits a file into segments and gives each segment an ID. This is used for queuing segments after each other and also to check that all segments have been received, while resending segments which were lost during the transmission. However this creates a small overhead making TCP slower than UDP and not useful in certain situations. UDP on the other hand splits data into segments and sends it one after the other. It does not establish a connection and does not resend lost segments. This is useful making this protocol consume less bandwidth and also ideal for streaming video and voice.

Ports

Ports are specified in the packet header. These packets contain a source port and destination port. The number of ports range from 0 to 65535. The numbers from 0 to 1023 are known as the well known ports and are defined by the Internet Assigned Numbers Authority (IANA). These are a list of reserved ports which cannot be used for anything else except for already defined service. Among these we find port 80 (HTTP), 443 (HTTPS), 20 and 21 (FTP), 22 (SSH), 23 (Telnet), 25 (SMTP), 110 (POP3), 143 (IMAP) and more. The numbers above 1023 are used for other purposes, such as the source port from a client browser and also for testing such as the normal use of port 8080. When a browser needs to connect to a web server to show a website, the TCP protocol issues a source port with a number greater than 1023, such as port 25000, and a destination port of 80, the default port of a web server. Ports belong to the Layer 4 of the OSI Layer Model seen below.


Figure 3: The OSI Layer Model

Domain Name System

Domain Name System is a hierarchical distributed naming system for computers, devices and other resources using IP networks. DNS translates queries for Domain Names, words which human beings are used to understand and remember quickly into IP addresses, which are a series of numbers without any particular meaning and extremely hard to remember. This service can be used over the internet to reach websites and resources, such as www.google.com instead of using its IP address of 173.194.35.176, and Daniel-PC instead of 192.168.1.79.


Figure 3: DNS Hierarchy Example

This system uses a system of hierarchy. This means that it consists of zones underneath each other. At the top we find the root of the DNS, the . After this there are the top level domains, .com, .net, and more. Then there are the domain names, such as eurosport, google and more. After these there are the sub domains such as premierleague, mail and more. These will be formed like this: premierleague.eurosport.com and mail.google.com. The . at the end is omitted. When there is a request for mail.google.com, there will be a request to the root DNS server which replies with the address of the .com DNS server. There is a request to this server for the same address to the .com DNS which in turn will return the address of the google DNS server. Then this server will return the address of the mail.google.com because he will be the authoritative DNS for the google.com domain and he will know the exact address of the mail.google.com server. This example is illustrated below

Figure 4: DNS Request Example