IP Canonicalization in Nginx Http/Https:
IP canonicalization is to redirect IP Address to the domain. This actually a part of SEO, so good to have IP canonicalization, but you can’t achieve this using shared web hosting.
IP Canonicalization in Nginx Http/Https:
Add the below block to above of your default server block in your nginx conf file, which is default available in /etc/nginx/nginx.conf
This below block works for both http and https IP canonicalization in nginx server.
[code]
server {
listen *:80;
listen *:443 ssl http2;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate “/etc/letsencrypt/live/ngdeveloper.com/fullchain.pem”;
ssl_certificate_key “/etc/letsencrypt/live/ngdeveloper.com/privkey.pem”;
server_name 18.218.X.X;
return 301 https://ngdeveloper.com;
}
[/code]
Note:
- Please mention the actual path of the ssl certificate.
- Do not forget to restart the nginx server.
How to Test ?
If https:
[code]
curl -I https://18.218.x.x -k
[/code]
If http:
[code]
curl http://18.218.x.x
[/code]
You can also use this website to check IP canonicalization Test online.
So If you have hosted your website in a shared environment, then it won’t be possible, because the same IP could have shared to many.
If You still want to achieve then plan to buy a private IP then try to achieve.