Report this

What is the reason for this report?

My website is Loading via Domain, but i cant load it via IP address, i keep getting error 404.

Posted on December 11, 2024

My website is Loading via Domain, but i cant load it via IP address, i keep getting error 404. And all the dns look ups are fine.



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!

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.

Hi Samuel!

If your website loads via the domain but gives a 404 error when accessed via the IP address, it’s likely due to how your web server (like Nginx or Apache) is configured.

Basically, web servers use Virtual Hosts (in Apache) or Server Blocks (in Nginx) to map requests to the correct site based on the domain name (the Host header). If no specific configuration matches the IP address, the server returns a default 404 error.

To learn more about virtual hosts and server blocks check out these two articles:

For Nginx:

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

For Apache:

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-20-04

To fix this you will have to check a few things:

  1. Check Virtual Host or Server Block Configuration
    Make sure your server configuration includes a default host that serves your website when accessed via the IP.

    For Apache:

    <VirtualHost *:80>
        ServerName your_domain.com
        ServerAlias your_server_ip
        DocumentRoot /var/www/html
    </VirtualHost>
    

    For Nginx:

    server {
        listen 80;
        server_name your_domain.com your_server_ip;
        root /var/www/html;
    }
    
  2. Restart the Web Server
    After updating the configuration, restart your web server:

    sudo systemctl restart apache2   # For Apache
    sudo systemctl restart nginx     # For Nginx
    
  3. Check Firewall Settings
    Ensure port 80 (HTTP) or 443 (HTTPS) is open:

    sudo ufw allow 'Apache Full'    # For Apache
    sudo ufw allow 'Nginx Full'     # For Nginx
    
  4. Verify the IP Address
    Confirm you are using the correct public IP of your server.

Feel free to share more details on your exact setup and the guides that you’ve follow to set it all up and I can give you more information on how you could solve this if the above does not work.

Let me know if this helps!

- Bobby

Heya,

This is entirely up to your Nginx/Apache configuration. Can you share which one you are using? So, basically, it’s not related to your Domain but your WebService configuration file.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.