Using Multiple Domain Names - Linux Web Server Development (2015)

Linux Web Server Development (2015)

Chapter 11 Using Multiple Domain Names

A virtual server was configured in the previous chapter to provide two rules for different content types (html and php). In this chapter we will configure a server to provide two rules: one rule that accepts connections on port 8080 and one rule that accepts connections on port 8181. Recall that we now have two registered DDNS domains:

· webserver.dynu.com that uses port forwarding on port 8080

· christos.dynu.com that uses port forwarding on port 8181

For a given request for a resource, Cherokee will look in its rules for a match with the requested domain name.

Applying Multiple Rules

In the vServers section of the Cherokee Administration Panel, click on the Add New Virtual Server button (the blue plus sign button). In the dialogue window that appears, enter in the Nick textbox One Server with Two domains and in the Document Root textbox the value /var/www3. Click on the Add button. In the Basics tab of the vServers section, enter index.html in the Directory Indexes textbox.

Click the Host Match tab and in the Method drop-down menu, select Server IP. Click the Add new IP/Subnet button that appears and in the dialogue window, enter the private IP of the Web server (e.g., 192.168.1.101) and click the Addbutton.

The server’s private IP address is now reflected in the IP or Subnet textbox.

Next click the Behavior tab and click the Rule Management button. A new set of tabs (Rule, Handler, etc.) appears. In the left area of the Administrations Panel you can find the Default rule as well as some predefined rules.

Click on the ‘x’ button to the right of the rule names to delete the predefined rules. Also click Delete in the pop-up window that appears. You cannot delete the Default rule. Click next on the Add Behavior Rule button (the blue plus sign button at the upper-left area of the window) to add a new rule. In the dialogue window that appears, click Manual in the list on the left and select Incoming IP/Port from the Rule Type drop-down menu at the right and then choose one of the ports on which the server currently listens (e.g., 8080) in the Incoming IP/Port drop-down menu that appears. Click the Add button.

The Rule tab reflects those settings and allows you to change them.

In the Handler tab, select the handler for this rule. For this example in the Handler drop-down menu, select Server Info. In the Show Information drop-down menu that appears, select Server Information. This time, the virtual server instead of static content or dynamic PHP content provides some info about the Web server itself.

We need another rule. Click again on the Add Behavior Rule button.

In the dialogue window that appears in the Rule Type drop-down menu, select Incoming IP/Port again and choose the other port number that we are using for the server, namely port 8181, in the Incoming IP/Port drop-down menu. Click the Add button.

In the Handler tab, select Only Listing.

Finally, click the SAVE button in the upper-left area of the window and then select Graceful restart in the dialogue window that appears.

Testing the Virtual Server using multiple URLs

To test your virtual server, you will use tools.pingdome.com again. Before you start the test, remember to enable port forwarding for the two domain names. In the previous examples this would be port 8080 for webserver.dynu.comand port 8181 for christos.dynu.com. In the text field, enter webserver.dynu.com. Click on the Test Now button to start the test.

The result includes information about the Web server:

Run the test again, this time using the URL christos.dynu.com:

The result is a listing of the Document Root directory:

Note that the responses in both cases are what would be expected, considering the rule handlers that were set.

In this example there is a difference between the two domains, webserver.dynu.com and christos.dynu.com, since they do not provide the same content – in contrast to the previous examples. The reason for this is that DDNS redirects requests for each of those domain names to a different port and a different handler is associated with each port.