How to redirect droplet IP to Domain Name ?

July 10, 2015 4.7k views
DigitalOcean Apache

My droplet can be visited from both IP & Domain

I am using Cloudflare with my Droplet. (https://www.youtube.com/watch?v=iWaFAIRWsA4)

I want to redirect my ip to my domain

I am using Wordpress (Linux on Ubuntu 14.04) on Apache Server

3 Answers

Not really sure exactly what you are asking... I am using the same set up as you I am using Wordpress (Linux on Ubuntu 14.04) with Cloudflare What exactly are you wanting to do? You have said that My droplet can be visited from both IP & Domain and that is correct no? but yet you added I want to redirect my ip to my domain I'm confused. You have been a little vague about your issue and somewhat confusing having stated that you can visit your domain from your IP address and Domain (assuming you're referring to domain name)... that would be a correct set up, hence confusing?

  • Hi ,

    I am asking that I just want to redirect my droplet's public ip (128.199.xxx.xxx) to my domain for the visitors if they try to visit my site on my ip

First off, have you set up your DNS records correctly so that your domain name points to your IP address?

Type                   Name                         Value                                                TTL
A                   example.com  your droplet IP address       Automatic

CNAME        www                example.com                        Automatic

If that is done, then how is your server block defined? ....Does it look like this?

server {
        listen 80;

        server_name YOURSITE.WHATEVER;

If you are set up like this, then I see no reason why you shouldn't arrive at the same location regardless of what is entered into the address bar. Yours may look a little different as I am using Nginx, not Apache.

Sorry... couldn't get my answer to format correctly and by the time I had messed around changing it, DO marked it as spam rolls eyes

Make sure your DNS records are set up correctly...
A record lists your domain name pointing to your droplet IP address.
CNAME record lists your www pointing to your naked domain name

In your server block, check that your domain name is listed as your server and you should be good to go. Not much point in me showing you my config for the server block as I'm using Nginx and its a little different to Apache. If you have done that, then I see no reason why if someone enters your IP address or your domain name, they wouldn't resolve to the same location, because that is all I have done and it works for me.

Good luck.

Have another answer? Share your knowledge.