Question

How to Have Site Display Domain Name instead of IP

Posted October 10, 2021 105 views
NginxWordPressDockerDNSCMS

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.

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.

×
Submit an Answer
1 answer

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

  • Hey there Bobby,

    Thanks for the response!

    I tried out those steps in order but I’m still getting a too many redirects error. I don’t have any 301 redirects in my nginx.conf file and I don’t have any wordpress caching plugins, so I’m not sure what the problem is.