Restriction of access on HTTPS to any website via IP Address on NGINX

It is recommended to access any web site via domain address instead of IP address, therefore please use the following steps to configure your NGINX.

server {
listen 443 ssl;
server_name test.com

ssl_certificate /etc/nginx/ssl/test.com.crt;
ssl_certificate_key /etc/nginx/ssl/test.com.key;
if ($host != "test.com") {
return 301 $scheme://test.com$request_uri;
}
}

After configuration is saved, reload your NGINX:

# service nginx reload

After NGINX reloaded, It will redirect all direct accesses using IP address to https://test.com along with the URI in the request.