Replace my ip address with domain name.

December 21, 2014 7.9k views

I have setuped everything and is working very well. Now what I want is when a user enter ip address of droplet the url should be rewritten with my domain name.

I have created A record and CNAME record and the people can access it with ‘www’ and without 'www’. The only functionality I need is that to replace my ip address in the address bar with domain For Ex:- to

Please Help ASAP

2 Answers

Y.ou need to create a virtual host directive for your domain. Since you didn’t mention your server OS, please check these fine tutorials from DO:

by Etel Sverdlov
This tutorial shows you how to set up virtual hosts. Virtual Hosts are used to run more than one website or domain off of a single server and IP address. When used with nginx, virtual hosts are called Server Blocks. This tutorial covers setting up server blocks on a Centos server.
  • I tried the above link but it wasn’t working! I followed steps described in the tutorial but no success

    My Server OS is Ubuntu running nginx

  • If you want to redirect your IP address to your domain name, the server block should look like this:

    server {
        listen 80;
        server_name IP;
        return 301$request_uri;


    server {
        listen 80;
        return 301$request_uri;
  • Thank you It solved my problem

Have another answer? Share your knowledge.