Hari's Corner
Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and thenLinux self webhosting - HOWTO
Filed under:
Tutorials and HOWTOs by
Hari
Posted on Fri, Apr 13, 2007 at 14:28 IST (last updated: Thu, May 7, 2009 @ 21:00 IST)
In this series | < Previous |
Step 1: Install a safe firewall configuration
In case you're not behind a router, you would need a firewall to block services not absolutely required for the outside world. If you are behind a router, then you won't need a firewall, but I still recommend one just as an added layer of security. A good idea would also be to simply disable any services running on the system which are absolutely not needed. You don't absolutely need a firewall if you don't have any other services running on your machine which you don't want to expose to the outside world. Guarddog is a great GUI firewall program that can configure an iptables firewall in double quick time. Install it and configure your firewall. The GUI is extremely intuitive and you won't need to know anything more than what services you want enabled (both incoming and outgoing from your machine). Make sure that all the services you need are enabled in the configuration and then apply it. While configuring make sure you enable HTTP from local to internet zone. If you're good enough to use iptables directly, then you may not even need my helpStep 2: Install a webserver
There are many webservers you can use. If you're not really comfortable with Apache or simply don't need its added power you can install a really light-weight, no-frills webserver like boa or lighttpd. If you're a user of Debian or Debian-based distros simply type:apt-get install boa
From the command line and you're done. Or use the package manager of your distribution to get it or simply compile from sources.
Now make sure your webserver is working properly by typing http://localhost
on your browser window. You should get whatever is the default home page of your webserver.
Add a index.html file in /var/www/
directory. You can also create a public_html
directory in your normal user's home directory. You can access this by typing http://localhost/~user
. Add whatever other web pages you wish to serve in either /var/www
or (if you've enabled user directories) /home/user/public_html
where user is your user name.
Step 3: Get a host name at DynDNS
Although you can set up your own name server if you have a domain name, you can also use DynDNS which is very convenient for dynamic IP hosts. Create an account. Log in and click on the "Dynamic DNS" link and click on "Add host." Type in the name of your website and choose an appropriate domain name (you have plenty of choices) and add it. Your current IP address will get hooked to it. That's all! You're now almost ready to host your website. If you have a static IP, you should probably create a "Static DNS" instead of the dynamic one.Step 4: (If behind a router) Port forwarding
You can avoid this step if your machine has a direct static IP to the internet. Most likely in a home system, this is rare. If you're connected to the internet using any router, you need to follow this step. This is the trickiest part of the whole setup. But don't worry. If you're using a router, then you need to get into the web administration panel of your router. Open a browser and type the internal address of your router (usually http://192.168.1.1) You will be prompted for the username/password of your router to proceed further. Say your local machine IP is 192.168.1.10 and your router internal IP is 192.168.1.1. Your machine is like a client in a LAN and you need to make sure it can be reached from the outside world. Port forwarding is how you do this. By forwarding different ports, you can enable different services from your machine to the outside. These are the general settings you would need to set in this screen:- Name: Any descriptive name for the service, say HTTP.
- Private IP: 192.168.1.10 (the internal IP of your machine acting as the server)
- Protocol type: TCP
- Public port: 80
- Private port: 80
- Enabled: True (usually a check-box or a radio button)
Step 5: Testing it all out
Since you're behind your own webserver, you cannot test whether everything works well from your this system. Get another internet connection on a different PC and check the URL (which you created with the DynDNS account) in a browser. If everything has worked well, you should see your own home page now. Congrats. If something is wrong and it doesn't work out, you should probably check whether you've done the previous steps properly. To access your website from the server itself, you should probably typehttp://localhost
in your browser window.
Finally some points to note
- Make sure that the internal IP of your machine acting as a server is static. That is, if it is 192.168.1.10 ensure that it will always remain 192.168.1.10 and not get reassigned by the DHCP on your router later on.
- Whenever your router's external IP changes, you will need to go back to the DynDNS dynamic host setup page in your account and edit it once again to reflect your current IP. This is probably needed only when you restart your router. If your website for some reason is not loading even after you've set everything up properly, this is probably the cause (DynDNS may be convenient, but it's not magic!) You can also use convenient client scripts which does this for you automatically. ddclient is one such script that is available in Debian.
- If you find that your internal relative links in your website point to the local host name of your system instead of its WWW URL, then you probably should make some webserver configuration changes. If you're using boa, do this
- Edit
/etc/boa/boa.conf
. - Find and uncomment the
ServerName
setting and change this to the DynDNS URL you created (without the http or the www part. e.g.harishankar.homeunix.org
). - Restart the webserver. Usually doing
/etc/init.d/boa restart
should do the trick.
- Edit
- You might probably want to configure your webserver to allow only a limited number of connections at a time if you're on a slower connection. Check your webserver configuration for this.
In this series
- Linux self webhosting - HOWTO
- Web hosting tips revisited
- Choosing a web hosting solution
Comments closed
The blog owner has closed further commenting on this entry.
5 comment(s)
Comment by J_K9 (visitor) on Fri, Apr 13, 2007 @ 16:03 IST #
Comment by hari (blog owner) on Fri, Apr 13, 2007 @ 17:10 IST #
Comment by hari (blog owner) on Fri, Apr 13, 2007 @ 17:17 IST #
Comment by drew (visitor) on Fri, Apr 13, 2007 @ 21:12 IST #
Comment by hari (blog owner) on Fri, Apr 13, 2007 @ 21:37 IST #