Monday, August 13, 2012

Reverse Proxy Apache

In the world of servers its a known fact that web applications tend to slow when only one server performs everything , cost of moving to another servers tend to be great and downtime tends to become an over kill too.
    To fight with something like this people came up with the idea of reverse proxy , now reverse proxy could be imaging just like a proxy server , but unlike bywhat.com , or ninjacloak.com, reverse proxy actually grants anonymity the web application server making it impossible for user to detect which server is actually serving web applications and which one is serving static content.

Lets have a look at typical diagram:



Lets look at how it works :
 User types in something like say www.shyam.com and the code is hosted over server A1
 While Another user types something like www.techblog.com and the code is hosted over A2

Now anyone who knows anything about webserver and a little networking will tell us , that if i simply ping www.shyam.com I will get an IP belonging to A1 server and for techblog.com i will get the ip of A2 server. 

But what if i say you ping both the websites the ip will be from the proxy server ? 

Some of us have understood what i am talking about , Others are probably scratching head and going how can that happen ?

This happened because we implemented three things:
  1. pointed A name entry of both to proxy server
  2. Then set up virtual host configuration to www.shyam.com and www.techblog.com on proxy server 
  3. Made an entry in the proxy server list 
Now here is what I followed.

  1. I installed an Apache server  and put in the code in this server lets call it A1
    1. At this point , I set it up with a virtual-host configurations ( a little demostration meant for another post )
  2. I did a similar thing with A2 
  3. Then made entries in the /etc/hosts for the proxy server 
  4. Then I made a simple modification set on the server side for proxy server 

This is an entry meant for www.shyam.com

<Proxy "*">
    order deny,allow
    allow from all
</Proxy>

ProxyPass / http://www.shyam.com/
ProxyPassReverse / http://www.shyam.com/
# for IE hosts
SetEnv proxy-nokeepalive 1
ProxyPreserveHost on










Tuesday, June 5, 2012

Virtual Host: multiple domain names on a machine Part I

PIN code is an address identifier to your location , Similarly an IP address , is an address that identifies a machine , Most of the interaction of a user to any machine is based on IP address.

Domain name service lets you map a Domain Name with an IP address , which means one can use a simple to remember a domain name and not remember the IP address. A server is usually a costly resource so what a hosting company simply does is hosts multiple domains on one machine. This way they can simply give a slice of hard disk space of a machine to a single user. This way an expensive resource can be utilize to maximize profits.

Lets see how you can do it , with Apache Virtual host configuration. This is not a post on automatic virtual configurations.

There are two ways of doing this one is the hard way:
  1. Create a new file in folder 
    1. /etc/apache2/sites-enabled
    2. Paste in following code 
    3. <VirtualHost *:80>
        DocumentRoot /home/shyam/workone/
          ServerName workedhost
            <Directory "/home/shyam/workone/">
              allow from all
                Options +Indexes
                  </Directory>
                    </VirtualHost>

                  1. at this point simply do
                    sudo a2ensite nameofthefile or
                    simply do a symlink of this file in site-enabled folder in /etc/apache2
                    works in ubuntu this way
                  2. Lets analyse this perticular code 
                The first line virtualhost directive  with * which signifies the address on which this domain name will be processed , In this case its any address associated with the servers ip address

                Now the next thing is :80 , his signifiies the port on which the hosting is going to be done 


                After this you have a directive called the DocumentRoot

                This directive shows where the server files are going to be stored
                Now lets look at the directory directive :

                With this we have attribute thats showing a path to DocumentRoot directory , This is done so we could apply some rules to this directory ,
                Current rules are

                apply from all , this allows all host names to access this files
                Options +Indexes Means it will look for default index file in the perticular directory


                Now you are ready to have a virtual host in ubuntu


                In case of any other OS , you could try putting this in Apache.conf(windows) or httpd.conf(fedora) file

                Of you could simply write this in a file and load it  with
                 Include "relative or absolute path to file"


                This in the first , or what i call manual case , Lets cover how to do it easy using a tool called webmin , Make sure you keep and Eye out for that post , You will see lots of things that can be done easily with out any hassle

                Thursday, May 17, 2012

                Hosts file : DNS server for local machine

                In age of internet , one who does not have domain name , does not have existence. This was line i heard in a movie, Cool as it sounds not really true yet , but eventually may become true.

                DNS , Domain Name System , was introduced to identify as machine with a name that one can remember  , and not a machine readble  address like "127.0.0.1" . While its just set of 4 numbers , a name like google.com is always easier to remember than 173.194.36.49. See what I mean ?


                 Domain name system works for the whole internet  , But one can make such a thing just for one's computer , This is done by something called a hosts file. Every Operating system has it , usually in a folder called etc , Although this folder can be deep within in your system. but this file does exist.


                Lets us see how we can use this file to do things we want to do.


                Lets say you want to play a naughty joke on your friend , so when he types in www.yahoo.com , you want him to see google.com , Here is how you can do that.

                1. First you need access to the machine on which you want to play this joke.
                2. Find the hosts file locations are specified below 
                  1. Windows
                    usually located on C:\windows\System32\drivers\etc\
                  2. Mac and Linux
                    Usually located in /etc/ folder in root 
                3. Now open the file in administrator privilege
                  and now add entries to it so that you can stick yahoo to may be something like google.com
                4. Now save and watch the magic happen
                here is a pictographical walkthru

                1. Open hosts file using a text editor , In linux you may have to run this command with sudo

                2. Open the hosts file using the text editor

                3. Now edit the file to map the domain name





                4. Now for the result


                Please do comment :)

                Any suggestions to make this more easier to understand will be appreciated.









                Wednesday, May 16, 2012

                Junction : Symblink on windows

                Symbolic links are very nice thing with Linux , On windows on the other hand this is not really done so easily , but a tool i came across an year ago which makes things very easy.

                It called Junction and is available on this website 
                1. http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx

                2. You have to download this to you machine , I downloaded and extracted it in my c:\Junction folder
                3. Use CMD to get to this directory


                   I lookup help on this tool by running /? as a wildcard
                4. Then simply run
                  Junction <target directory> <Junction target>



                  Now it will show you created and targeted as shown above
                5. Now test it out , by opening the directory

                Now you are ready to use the junctions and Symbolic links as per your need :) 

                Please do comment :)

                Tuesday, May 15, 2012

                Virtual Box disk resize



                We always run into deadlocks when we need extra space on virtual machines and since the hdd is already created it becomes a problem to re size a disk. lets walk through a fast way of doing so.Using VBoxManage and Gparted

                if you find reading as a boring habbit just follow the pictures :)




                1. Open a terminal and CD into your existing virtual disk, the location of the disk can be  found out by using step number
                2. Now create a new disk using
                  VBoxManage createhd --filename newone.vdi --size 3000
                   Where newone.vdi is the disk name if you see image above you can make anytype of supported image which means this method can also be used for vmware disks
                3. Now copy  contents of the disk which needs to be resize into this one using command
                  VBoxManage clonehd packed-disk2.vmdk newone.vdi --existing
                  where packed-disk2.vdmk is the original disk (10 gb )
                  newone.vdi is the new 30 gb disk
                4. Now open settings of virtual machine in question
                5. Now find the storage controller and the hdd

                  this can be used to locate the disk which needs to be resized

                  Now change this hdd


                  Remember your old disk still remains so if all this effort fails you can always switch back
                6. Now load the gparted iso file in the virtual machine

                  Same way the hdd was replaced , but this time choose the cd/dvd controller
                7. Now boot up the virtual machine

                  press f12 to get above screen then press c to select cd
                8. Now you will see gparted screen for booting

                  select 1st options and press enter
                9. Now gparted shows you some options like keyboard layout , screen resolution , type of card and how to start x server
                  my answers were 
                  1. Dont touch the keymap
                    1. Selected 33 us english
                  2. start of the x server automatically
                  3. resolution os 1024 X 768
                  4. depth 24 bit 
                  5. Vesa card
                10. Now you will see desktop , select Gparted icon

                  Will give you a screen like this , this point onwards you can right click the partition you want to resize or move and move then. Rules of using Gparted are kinda rigid , but are straightforward
                  1. you will have to adjust the partitions according to whats in front and behind the disk
                  2. and move them like a puzzle till you get what you want , the disks can be graphically resized
                11. Here is how it looked while processing
                12. Here is how it looked after the partitioning was done
                13. This is how the disk utility looked after i booted my virtual machine

                now after this you can either keep the earlier disk or delete it  , If the process goes wrong , then you can always restore you virtual hdd the way it was done in step 5 and you will have restored the hdd


                Please do comment :)

                Ubuntu 12.04 boot up problems

                Ubuntu 12.04 boot up problems on fresh install 
                I decided to give ubuntu 12.04 a spin , bought a new laptop recently to try out the power of core i5 , Since ubuntu is one of my most favorite , I decided to dual boot it  like i did with my last one.

                Everything went smoothly I installed my games , softwares on the Windows , then went on to install ubuntu with a usb stick , I have no clue what problems Ideapads have with Ubuntu , but the first screen , did not show properly , but having idea of what is there on the boot menu i simply hit enter on the boot menu.


                Following this i was greeted by the live cd environment of ubuntu , on which i selected install , so as to install it directly. From this point onwards everything was smooth and fast as usual. Easy selection screens  and the install was complete.

                But as soon as i hit restart , the boot loader did not show up , which should have happened automatically. As of writing of this article i have no clue why this happened . This perticular issue did not take place with a full fresh install of ubuntu 12.04 on a desktop done by a friend earlier.

                Then i went googling for solution as usual came up with a solution that works , will keep a reference link so you guys can look into that blog post too


                This is what i did in steps:

                1. Booted the machine using the Live-CD 
                2. I checked whether 12.04 got installed , did this with help of Live-CD , booted into live cd and started up disk utility and looked for linux partitions on the HDD 

                My disk utility screen showed something like above , Now i needed to know which partition root was mounted on , that i got by clicking the right partition with ext format 
                1. From this point on everything was downhill. I
                2. Mounted the partition using
                  sudo mount /dev/sda1 /mntsudo mount /dev/sda5 /mnt/boot # this step i did not do I think i did not need it since the boot loader files are installed in the /boot folder of root 
                3. Then simply installed the Grub loader in the boot sector
                  sudo grub-install --root-directory=/mnt /dev/sda

                /dev/sda is the disk address where the boot manager is going to be installed. This is very important since this will write your MBR to get the boot loader working 

                Then i simply rebooted the machine to be greeted by the Grub loader at the start. And thus my experience with 12.04 started 



                There seems to be a faster and an easier way of doing the same ,and is available here 
                Used commands referenced here 





                Wednesday, April 11, 2012

                Display export problems and how to access display

                HOST+ Amazing work .



                I use this little trick when i need to keep my profile clean i may end up inspiring some one , to do something they are not allowed on their machine :) . ;) 


                1. Create an account on your linux machine 
                2. Then type xhost+
                3. This will allow the new user to run application using the your desktop
                4. Now log on to that user and simply start the application you want to work with. 


                Illustrations below




                Compiz effects





                In my previous post earlier today i talked about compiz cool effes now i am going to take some time to show some of them off.


                One of these perticular that i like is expo


                It allows one to see the bigger picture , it allows you to see all your ope

                n windows all at once and which workspace your are running it , No limit of workspaces what ever your linux allows it will work. I use Super + S to do this you can change this shortcut from Compiz manager







                The next cool feature on the expo is workspace drag, one can drag windows from a different workspace







                The expo tools is also available in 10.04 with effects enabled used the same button super + E







                Using expo to move applications from one workspace to another