• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Nginx WordPress : Redirect to Geographically Closer Server

By Abhishek Ghosh November 17, 2016 11:00 am Updated on November 17, 2016

Nginx WordPress : Redirect to Geographically Closer Server

Advertisement

Often we see many enterprise websites redirect users to country specific subdomain. Here is How To Setup Nginx WordPress to Redirect to Geographically Closer Server. This Setup is Known as Geo Redundant Setup of WordPress. This is only practical if your website has lot of traffic from various regions and you need to decrease load. There are two matters involved – one is setting Nginx as Traffic Director, second is setting each WordPress setup to sync with each other.

 

What Backend Needed to Redirect to Geographically Closer Server With Nginx WordPress?

 

First, ideally you need a Geo Redundant DNS like dyn with Traffic Redirector, Nginx Plus (contact either Nginx or us) and a CDN with lot of PoP like KeyCDN. Actually Dyn has higher DBS service to work as Traffic Director themselves, that is not available with the normal paid account. If you do not use Dyn’s Traffic Director and Nginx Plus still you can follow our guide. You need a good DNS and Nginx community edition as minimum need.

For this guide, you need to follow the products we are suggesting. Otherwise page speed will be more slower. You need virtual servers in Europe from Aruba Cloud (because Aruba is bigger Italian brand with datacenter in UK and other areas), VPSDime as main server in US. This is normally enough – Global at US and one cluster in Europe. You can add one node in Malaysia server for Asia. You can check WebHostingTalk, LowEndBox websites for cheaper, unmanaged servers with 1Gbps to 10 Gbps network connection. Using DigitalOcean, Amazon etc will result in very slow result because their datacenter in each region are not exactly fast. Except Dyn, we suggested cheaper servers. CDN is a normal need.

Advertisement

---

As commonly we use W3 Total Cache Plugin to create cached HTML files and serve static files with CDN, you need to calculate the profit with the amount of work. We have to sync WordPress MySQL database with main server as well as the FTP content. For FTP live data replication using lsyncd solves the matter.

WordPress and MySQL both has ways to sync MySQL database. If you use a specific function (like a pop up for EU but not for the other areas, different design etc) for one geographical area, then you need to manually update the posts after initial setup. For our guide :

Vim
1
2
Main server : thecustomizewindows.com, US; Incero colocation hosting
EU server : eu.thecustomizewindows.com, Italy; Aruba Cloud

From Dyn DNS or other DNS service, we have to point eu.thecustomizewindows.com subdomain’s server in EU.

nginx-wordpress-redirect-to-geographically-closer-server

 

What Nginx Settings Needed to Redirect to Geographically Closer Server With Nginx WordPress?

 

This step is when you are not use any external traffic redirection service at DNS level. As first call is to US server (thecustomizewindows.com located at US in our example), thereafter getting a redirection to EU, it is not exactly optimal. However, it is great for marketing purpose like serving specific Ads. We have a guide on Nginx Geo-IP setup, please follow it for all servers you’ll have.

Extra than that guide you need to create a special fast CGI cone file (usually the normal file is /etc/nginx/fastcgiparams) :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
fastcgiparam REDIRECTSTATUS 200;
fastcgiparam GEOIPADDR $remoteaddr;
fastcgiparam GEOIPCOUNTRYCODE $geoipcountrycode;
fastcgiparam GEOIPCOUNTRYNAME $geoipcountryname;
fastcgiparam GEOIPREGION $geoipregion;
fastcgiparam GEOIPREGIONNAME $geoipregionname;
fastcgiparam GEOIPCITY $geoipcity;
fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code; #EDIT
fastcgiparam GEOIPAREACODE $geoipareacode;
fastcgiparam GEOIPLATITUDE $geoiplatitude;
fastcgiparam GEOIPLONGITUDE $geoiplongitude;
fastcgiparam GEOIPPOSTALCODE $geoippostal_code;

You can name it as /etc/nginx/fastcgiparams_geo and include in all server’s virtual hosts file where include fastcgiparam; exists. You can add the above stuff to existing /etc/nginx/fastcgiparams like file too as alternate way.

For our main server, thecustomizewindows.com located at US, with two servers thecustomizewindows.com and eu.thecustomizewindows.com, we will map in this way (take it as master config) :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
map $geoip_city_continent_code $closest_server {
  default thecustomizewindows.com;
  AF      eu.thecustomizewindows.com;  # EU is closer to Africa
  AS      eu.thecustomizewindows.com;  # EU is closer to Asia
  EU      eu.thecustomizewindows.com;  # Europe
  NA      thecustomizewindows.com;  # North America
  OC      eu.thecustomizewindows.com;  # Calculate if EU is closer to Oceania?
  SA      thecustomizewindows.com;  # US, NA is closer to South America
}
server {
  listen 80;
  listen [::]:80;
  root /var/www/domain.com/html;
  index index.php index.html index.htm;
  server_name  thecustomizewindows.com;
 
  if ($closest_server != $host) {
    set $test  A;
  }
  if ($host ~* $server_name) {
    set $test  "${test}B";
  }
  if ($test = AB) {
    rewrite ^ $scheme://$closest_server$request_uri break;
  }
  location / {
    try_files $uri $uri/ =404;
  }
# rest of the config

Obviously for EU server, the server_name becoming server_name eu.thecustomizewindows.com;. For the US server, you need slight modification by commenting out SA and NA :

Vim
1
2
3
4
5
6
7
8
9
...
  default thecustomizewindows.com;
  AF      eu.thecustomizewindows.com;  # EU is closer to Africa
  AS      eu.thecustomizewindows.com;  # EU is closer to Asia
  EU      eu.thecustomizewindows.com;  # Europe
  # NA      thecustomizewindows.com;  # North America
  OC      eu.thecustomizewindows.com;  # Calculate if EU is closer to Oceania?
  # SA      thecustomizewindows.com;  # US, NA is closer to South America
...

For the EU server, you need slight modification from that master config :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
...
  default eu.thecustomizewindows.com;
  # AF      eu.thecustomizewindows.com;  # EU is closer to Africa
  AS      eu.thecustomizewindows.com;  # EU is closer to Asia
  # EU      eu.thecustomizewindows.com;  # Europe
  NA      thecustomizewindows.com;  # North America
  OC      eu.thecustomizewindows.com;  # Calculate if EU is closer to Oceania?
  SA      thecustomizewindows.com;  # US, NA is closer to South America
}
# notice the redirection to main server
server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;
  server_name www.thecustomizewindows.com;
  return 301 http://thecustomizewindows.com$request_uri;
}
# notice the www redirection
server {
  listen 80;
  listen [::]:80;
  server_name www.eu.thecustomizewindows.com;
  return 301 http://eu.thecustomizewindows.com$request_uri;
}
# notice the working server block
server {
  listen 80;
  listen [::]:80;
  root /var/www/domain.com/html;
  index index.php index.html index.htm;
  server_name  eu.thecustomizewindows.com;

Run nginx -t and service nginx restart. Test with WebPageTest to check the regions and page speed. We gave a cost effective solution, but this may not be a secure setup.

Tagged With paperuri:(ff0014673d3d9508c1cdd94908348982)

This Article Has Been Shared 165 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Nginx WordPress : Redirect to Geographically Closer Server

  • Cloud Computing Benchmark

    Cloud Computing Benchmark Standard is needed to quantify and standardize the performance from various Cloud Computing service providers.

  • Juju Package Manager for Cloud Computing

    Juju is a Package Manager, service orchestration management tool developed by Canonical for development of Cloud Computing of your own. It is Open Source.

  • Platform as a Service : Careful About Disaster Recovery as User

    Platform as a Service is mostly free for the small scale App, CMS Hosting. New users must be careful about Cloud Computing Disaster Recovery as users of PaaS.

  • Changing Scenario in US Based Cloud Computing : The Business Aspects

    Changing Scenario in US Based Cloud Computing Will Render the Telecommunication companies to could become the wholesale suppliers of cloud services in future.

  • Price War in the cloud : The Actual War is Rackspace Versus Amazon

    Price War in the cloud is in practical World is Rackspace Versus Amazon as infrastructure provider or rather Open Source versus closed source. Let us look deep.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Proxy Server: Design Pattern in Programming January 30, 2023
  • Cyberpunk Aesthetics: What’s in it Special January 27, 2023
  • How to Do Electrical Layout Plan for Adding Smart Switches January 26, 2023
  • What is a Data Mesh? January 25, 2023
  • What is Vehicular Ad-Hoc Network? January 24, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Nginx WordPress : Redirect to Geographically Closer Server," in The Customize Windows, November 17, 2016, January 31, 2023, https://thecustomizewindows.com/2016/11/nginx-wordpress-redirect-to-geographically-closer-server/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT