Question

How to Have Site Display Domain Name instead of IP

Hello there,

I’m currently trying to get my site to display its domain name (which I’ll call example.com) rather than the ip address associated with it. I’ve looked at tutorial after tutorial, but I haven’t come across a solution. I’m using Nginx with Wordpress in a docker container running on a digitalocean droplet.

Currently, I have three NS records with hostname set to my domain example.com, and they direct to ns1.digitalocean.com, ns2.digitialocean.com, etc. I can visit my site by typing in example.com, but it then displays the ip address, and I want it to display example.com instead.

I’ve tried the following:

1.) I’ve tried going into my nginx.conf file and changing the server_name variables to my hostname instead of the ip address, but this doesn’t change anything.

2.) I’ve tried navigating to my wordpress wp-config.php file and adding

define('WP_SITEURL', 'http://www.example.com');
define('WP_HOME', 'http://www.example.com');

but this causes a ‘too many redirects’ error. I’ve also tried it without the www, but that also produces a too many redirects error.

What am I doing wrong? Does anyone know how I can get my site to always display the hostname over the ip address? Any help would be appreciated.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello,

I believe that you are in the right direction. I would recommend the following:

  • First change your Nginx server block to match your domain name and restart it.
  • Check your Nginx config files for any 301 redirects that could be causing the redirect loop that you’ve noticed.
  • After that add your Site and Home URLs to your wp-config.php file.
  • Clear your WordPress cache in case that you are using a caching plugin.
  • Finally make sure to clear the cache of your browser too to make sure that you are not seeing a cached version of your site, or visit the site via an incognito browser.

Let me know how it goes! Best, Bobby