1. Home
  2. Web Server
  3. How to configure IP Canonicalization on Nginx

How to configure IP Canonicalization on Nginx

If you had read our IP Canonicalization article, then you would have understood the importance of it. Recently, we migrated our website from Apache to Nginx web server. I had known about how to configure IP canonicalization in Apache, but didn’t knew on Nginx. After googling, I could do the same on Nginx as well. This guide will explain how to configure IP canonicalization on Nginx.

Configure IP Canonicalization on Nginx : redirect IP Address to domain name

Redirecting IP address to domain name is very important for SEO, which you would have learnt from our earlier article. So, here’s how you can implement IP canonicalization in Nginx.

Add the below server block as a new server block instance to the bottom of the Nginx configuration file.

## IP Canonicalization
server {
   listen <IP_ADDR>:80;
   server_name <IP_ADDR>;
   return 301 $scheme://domain.com$request_uri;
}

Test the Nginx configuration for errors and then Reload/Restart the Nginx

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# systemctl restart nginx

Test the IP Canonicalization for Nginx

Method 1: Now you can access the IP_ADDR in the browser to see that redirecting to the domain name.

Method 2: Using curl command as shown below:

$curl -I http://your-server-ip

HTTP/1.1 301 Moved Permanently
Server: thing
Date: Wed, 29 Nov 2017 12:21:43 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: http://domain.com/

You can see from the above methods, the IP address redirecting to the corresponding domain name.

Alternatively, you can use free online tools such as woorank.com or seositecheckup.com to check if canonicalization is working properly.

Note:

If your website is on a shared hosting, then the IP address will redirect to a page from Website’s hosting provider. It means, your domain will be using a shared IP address. In that case, you may need a dedicated IP address from your hosting provider to redirect IP address to domain.

Also remember, there’s no guarantee that IP canonicalization will improve your site’s search engine ranking, as the search engines never disclose which technique is hurting or improving your site’s ranking. To understand SEO problems on your site, you may useChrome Audit tool.

Updated on November 29, 2017

Was this article helpful?

Related Articles

Add A Comment