Accessing Apache Using Domain Instead of IP

To access your Apache server using a domain name (e.g., yourdomain.com) instead of the server's IP address, you'll need to follow these steps: 

 

Step 1: Point the Domain to Your Server’s IP 

  • You need to create an A Record in your domain’s DNS settings. 
  • Add an A Record with the following details: 

        Host: @ (or www if you want to add the www version) 

        Value: Your server’s IP address 

        TTL: Set it to Automatic or 300 seconds 

Step 2: Create a Virtual Host Configuration 

You need to configure Apache to recognize your domain. 

  • Create a new virtual host file: 

        sudo nano /etc/httpd/conf.d/yourdomain.com.conf 

  • Add the following configuration: 

<VirtualHost *:80> 

    ServerAdmin [email protected] 

    ServerName yourdomain.com 

    ServerAlias www.yourdomain.com 

    DocumentRoot /var/www/html 

    <Directory /var/www/html> 

Options -Indexes +FollowSymLinks 

        AllowOverride All 

    </Directory> 

    ErrorLog /var/log/httpd/yourdomain_error.log 

    CustomLog /var/log/httpd/yourdomain_access.log combined 

</VirtualHost> 

Note: Dont forget to create the directory  

sudo mkdir /var/www/vhosts/<domain_name> 

Step 3: Enable the Virtual Host 

After creating the virtual host, enable it. 

  • Apache automatically reads the configuration file, so just restart Apache:  

        sudo systemctl restart httpd 

Step 4: Test the Domain 

After DNS propagation and Apache configuration: 

  • Open your browser. 

You should see the Apache default page or your website content. 

 

Bonus: Instead of creating individual virtual host files for each domain, you can use mod_vhost_alias to dynamically handle multiple domains with a single configuration file. This is ideal when you have many domains and want a simpler, scalable setup. 

  1. Enable  mod_vhost_alias : sudo yum install mod_ssl -y
  1. Restart Apache: sudo systemctl restart httpd
  1. To use dynamic virtual hosts, you need to create folders corresponding to each domain:  
  • For example: sudo mkdir /var/www/vhosts/<domain_name> 
  1. You can repeat the same steps by creating virtual host and adding content into file: 

<VirtualHost *:80>

ServerAdmin [email protected] 

ServerAlias *.codetowebsite.com 
VirtualDocumentRoot "/var/www/%0/public_html" 
 
<Directory "/var/www"> 
    Options -Indexes +FollowSymLinks 
    AllowOverride All 
    Require all granted 
</Directory> 
 
ErrorLog /var/log/httpd/dynamic_error.log 
CustomLog /var/log/httpd/dynamic_access.log combined 

</VirtualHost>
 

  • apache, server, domain
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Backup restoration

Since backups are saved at various nodes to avoid data loss, we manage the backup and...

How To allow SQL Express traffic in windows firewall

Please follow the below steps to allow SQL express communication in the firewall. Open SQL...

How to change SQL authentication in SQL Express

Please follow the below steps Login to SQL Express using SQL management studio. Right-click...

Set Up Sending of Email in Plesk

To Set Up Sending of Email in Plesk, You need to follow the below Points   1. Go to Tools...

How to check Port status of VPS

It may possible that the firewall has blocked a few ports and it is not accessible.  To check...