The idea for this article came to me when we started working on a new version of the Zaltsman Media website. I needed to show the old version of the site to all users while working with the new version in our office, on the same server and using the actual domain.
To accomplish this, I made some adjustments to our Nginx server configuration. Before making these changes, the configuration looked like this:
server {
listen 80;
root /var/www/zalts-man.com;
index index.php.htm;
server_name zalts-man.com;
}
To display the old site to all IP addresses except ours, I renamed the folder containing the old site to “zaltsman_old” and placed the new site in a folder with the domain name “zalts-man.com.” Then, I created the following clever configuration:
server {
listen 80;
index index.php.htm;
server_name zalts-man.com;
root /$root;
if ($remote_addr = 78.82.189.130) {
set $root /var/www/zalts-man.com;
}
if ($remote_addr != 78.82.189.130) {
set $root /var/www/zaltsman_old;
}
}
As a result, all users with IP addresses different from ours saw the normal working site, while we, in the same server environment, were able to develop an even more impressive version of our website.