I am working on a project that host website for out client, something like wix.com. Our clients just need to update their domian's DNS records, and point to our server.
Because of scaling and other reasons, our server doesn't have a fixed IP address. So we create a subdomain (for example hosting.our-server.com), and ask our clients use CNAME records to point to us.

For www subdomain (for example www.client.com), its fine. However for naked domain (client.com), it doesn't work, because naked domain not support CNAME record, it must be A record.

Yea I know some new DNS service such as Cloudflare and AWS Route 53 support CNAME for root domain. However we cannot force our client to change their name server.

There is an existing service that doing such things, wwwizer.com. You just need to set their fixed IP address to your root domain, it will redirect it to www.you-domain.com. Its totally free.

However China is unpredictable, the IP address 174.129.25.170 which used by wwwizer.com is no longer accessible in China from Nov 2015. Look like redirect a root domain to www is so fucking danger, which endangering national security.

I search for similar service in China but can't find any. In my understand, due to ICP license, there is not possible to have such service hosting inside China.

So their is no other choices, I am going to clone wwwizer. Just get an Floating IP at Digital Ocean, setup a $5/mo machine just running Nginx for this shit.

People access the IP address directly, will redirect to our company website. Otherwise just add www in front of the domain and redirect.

/etc/nginx/nginx.conf

user  nginx;  
worker_processes  1;

error_log  /var/log/nginx/error.log warn;  
pid        /var/run/nginx.pid;


events {  
    worker_connections  1024;
}


http {  
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    #sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  65;
    keepalive_timeout 0;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/server.conf

server {  
    listen       80;
    server_name  "~^(?<domain>.+)$";

    # Floating IP
    if ($domain = "my_floating_ip") {
      return 301 http://www.example.com;
    }

    # Droplets IP
    if ($domain = "my_droplet_public_ip") {
      return 301 http://www.example.com;
    }

    return 301 $scheme://www.$domain$request_uri;
    expires 1y;

}