Testing a website from server before DNS switch via SSH Tunneling

This is a continuation to the blob I previously posted. Since then I have found another way of testing a site without switching the DNS.

What this approach does is, it assigns the port from the server (that you are migrating your site to) to a port on your local machine. And you can add your domain name on the hosts file with the 127.0.0.1 IP and you should see the site loading on your browser only. More details below:

Requirement: You need to have ssh access to your server obviously and have a tool on your local development PC that lets you ssh via command line.

  • Open the terminal and type the command below on your local PC.
ssh -L localPort:remoteServerName:remotePort [email protected]

localPort : is the port where you want the application to be mimicing on your local pc.

remoteServerName: Hostname of the remote server where your application is being setup and migrated.

remotePort: The port number on the Remote Host server where you application is being servers by Apache or other web server.

username: The user name that you will use to ssh to the remote server.
  • After doing the above, update your hosts file on the local development pc to point the domain name you are trying to test to 127.0.0.1 . example : 127.0.0.1 www.testsite.com
  • If you chose port 80 or 443 for localPort, then type the domain https://www.testsite.com on your browser and it should show the site that is running on the remoteServerName:remotePort.

You should now be able to test all your sites running on your servers using the above method via browser unlike the curl method mentioned in my previous port.


Testing a website from server before DNS switch via CURL

If we come across a scenario where we are migrating a high traffic site from a third party hosting provider like hostgator or godaddy to a IaaS host, we will come across a situation where we want to test if the site that we setup on the IaaS server is ready for us to do a DNS switch.

To accomplish that testing we can use ssh to the IaaS server and once all is setup we can test it using the curl command as below:

curl --verbose --header 'Host: www.mywebsite.com' https://ipaddress:port -k

–verbose will give you a detailed overview of the command

–header ‘Host: ‘ will allow us to tell apache2 which domain name are we trying to test.

Then we provide the https://[current ip]:[port] to tell curl that we want to check the response for the above domain name on this ip address and port.

-k will allow curl to ignore any SSL certificate issues if you havent finished transferring the SSL certificates to the server yet.