How do you run multiple web-servers on a single ip-address?

How does one run multiple websites of a single IP Address?

One way to do this is to use a server running Squid. The idea is that you point the router to go to the computer running squid when a request comes in for port 80. You then have to configure Squid to act as a ‘reverse proxy server’.  When I first did this I used Squid 2.7, so what I am about to write relates to that version of Squid. So follow the Wiki, or one of the tutorials on the internet, for installing Squid. The bit I found not well explained was the actual settings required in the Squid config file. So here is a way to look at what is needed.

The first bit is to set the server to service port 80 requests coming in from the router.  Use your favorite unix system editor to edit the file /etc/squid/config file. Locate the line containing the field ‘http_port, and change it to

http_port 80 accel vhost

Lets say your website server behind the router firewall  is called ‘websiteserver1’ and its on an LAN address of 192.168.1.10.  Then you need the following two lines in the Squid Config file:

cache_peer 192.168.1.10 parent 80 0 no-query originserver name=websiteerver1

Now you need to create a record that specifies all the websites that you want webserver1 to accept. Lets say the record for websiteserver1 will be called sites_webserver1. and the urls relating to that record are www.website1.net, www.website1.com , and website1.net. Then the following line is required:

acl sites_websiteserver1 dstdomain www.website1.net www.website1.com website1.net

Now we need to specify the configuration for the cache that Squid will require. This is done using the line:

cache_peer_access websiteserver1 allow sites sites_websiteserver1

Finally you need to let Squid now which websites it is supposed to handle. This requires the line:

http_access allow sites_websiteserver1

Make sure that the last line in the http_access is:

http_access deny all

This last line ensures that all websites not in the list preceding the ‘deny_all’ will be the only sites that Squid will accept.

If you have done this for a number of website servers, say three of them, you should have a set of lines that looks something like the following:

cache_peer 192.168.1.10 parent 80 0 no-query originserver name=websiteserver1

cache_peer 192.168.1.11 parent 80 no-query originserver name=websiteserver2

cache_peer 192.168.1.12 parent 80 no-query originserver name=websiteserver3

acl sites_websiteserver1 dstdomain website1.com website1.net

acl sites_websiteserver2 dstdomain website2.com website2.org

acl sites_websiteserver3 dstdomain website3.net website3.com

cache_peer_access websiteserver1 allow sites_websiteserver1

cache_peer_access websiteserver2 allow sites_websiteserver2

cache_peer_access websiteserver3 allow sites_websiteserver3

http_access allow sites_websiteserver1

http_access allow sites_websiteserver2

http_access allow sites_websiteserver3

http_access deny all

 

 

Adding or removing a command in Linux

So where do you add an instruction you want to run on startup in Linux? Well, it depends on when in the bootup-startup process you want it to run. If you want it to run just as it is initialising the gui (X11) then the best way is to create a file called ‘autostart’ in your /home/username directory. Then go to the script that controls the startup script for X11 and add the autostart file to that script.

As of 2016 you will find the startup script at:

/etc/xdg/lxsession/LXDE/autostart

Go to the bottom of this file and insert the instruction:

@/home/pi/autostart

This instruction will now cause the lx sesstion to run the startup  script in your home directory. Now go to your home directory and create a file called autostart. In this script add the command line you would like to run. For example if you want to run a http server at startup, you can add the line:

@python SimpleHttpServer 80

in that scrip.

Now, whenever you want to add a startup script to your system you don’t need to go hunting around the internet finding all those misleading tips—rather the startup script is right there in your home directory.

Changing the name of a linux system

So you want to change the name of a computer that is running Linux. Simple?
NOT… nothing is straight forward in Linux. Sure lots of programmers and IT developers will swear by Linux, but that doesn’t mean its straight-forward and neither is the documentation so spectacular either. Because so much of it is open-source you find all sorts of contradictory advice around the internet, and often it’s wrong anyway. So here is my attempt at contributing some consistency as I develop a few tutorials around some often encountered tasks.

This one is where you want to change the name of your Linux system so that when you look at your Local Area Network you will see the name of the computer rather than an IP address.
First you need to go to the file /etc/hosts. There you need to add (or change) the line

hosts 127.0.1.1 yoursystemname

Then you need to edit the file /etc/hostname and change the name to

yoursystemname