How to bind IP address to domain?

August 2, 2017 190 views
LAMP Stack Ubuntu 16.04

Hi, I can add domain to my dropplet using virtual host, but how can I point my IP address to the domain, let's say my domain is example.com, my IP address 111.111.111.111, now what I want is if I put 111.111.111.111 on browser, it will open example.com.

Thanks

4 Answers

My bad, what I mean is when I open 111.111.111.111 it will stay opening that IP address, but the content is similar to example.com

It seems I work it out, by creating virtual host with that IP address as a name, and example.com as the alias, pointing the same directory as example.com.

I have the opposite issue, the droplet IP shows one of the site not the default one ;)

  • Default means an empty one? Try to edit your ipaddress.conf to point new directory and put something there. If you don't have this you can create it.

  • Hi @Marvix

    If you've created a WordPress site, but you started by setting it up using the IP, then you need to modify your URLs in http://yourdomain.com/wp-admin/options-general.php so they are set to you domain instead of the IP.
    If you have a different problem, then please create a new question thread, so we don't cobble two different questions together.

Hi @MrWorldWideWeb

Create another VirtualHost for your IP and redirect to your domain:

<VirtualHost *:80>
  ServerName 111.111.111.111
  Redirect permanent / http://example.com/
</VirtualHost>
  • I see, so I don't need to put example.com as ServerAlias, just ServerName and Redirect. Thanks.

    • @MrWorldWideWeb

      If you put ServerAlias example.com then you would just create a loop, since you're listening to port 80 and redirecting to http://example.com/

      • How about using document root instead of redirecting it? So on browser it will still showing the IP address but the content from example.com, will it work?

        <VirtualHost *:80>
        ServerName 111.111.111.111
        DocumentRoot /var/www/example.com/public_html
        </VirtualHost>

        I tried this and it works, but I don't know if this is causing problem at backend process or not.

        • @MrWorldWideWeb

          But why would you want to have multiple ways to get into your site instead of redirecting everyone to the same end-point?
          You can do that configuration if you want.

Have another answer? Share your knowledge.