Problem with Virtual Host ( Virtual Host throws domain name not found error , if we call it from other computer )

My Question :

I would like to host two web application into single server but i am not having domain name but i have IP Address. and it is an Remote Server .

I use LAMP and i have created two Virtual Hosts for separate two web application and i have enabled that also.Suppose if my Server IP is 192.168.XXX.XXX , then

My first Virtual host and Second one is same as first but project name will be changed

<VirtualHost *:80> ServerAdmin webmaster@myfirstproject ServerName 192.168.XXX.XXX.myfirstproject ServerAlias 192.168.XXX.XXX DocumentRoot /var/www/html/myfirstproject/public <Directory “/var/www/html/myfirstproject/public”> AllowOverride all Allow from all Require all granted </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>

If i call with 192.168.XXX.XXX.myfirstproject/ in browser it shows Domain not found error , but i did the same process in my local machine , it work fine , why its not working if we called from other computer( Except locally ) and this is my /etc/hosts/ file content localhost
192.168.XXX.XXX 192.168.XXX.XXX.myfirstproject 192.168.XXX.XXX 192.168.XXX.XXX.mysecondproject

can you please help me where i am going wrong.

what my expected output is If i type 192.168.XXX.XXX.myfirstproject in browser it will load the content for myfirstproject and 192.168.XXX.XXX.mysecondproject in browser it will load the content for mysecondproject , But it working locally , but if i accessed from other computer it wont work , that was my problem .

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.

There are three types of virtual hosts apache supports. Name-based, port-based and ip-based.

Name based: This requires a domain name and uses the requested domain name to decide which site to show. You can get around this by making up a name and adding it to the hosts file on your local computer (not the server). On windows the hosts file is in C:\Windows\system32\drivers\etc while on Mac or Linux it is /etc/hosts. The name in /etc/hosts must be pointed to your droplet’s IP address.

Port based: You can run different sites on different ports but ports other than 80 and 443 would require you to specify the port in the URL. Do this by creating different virtualhost blocks for different posts. Your example shows a configuration for port 80 <VirtualHost *:80>

IP based: If you have more than one IP address available you can specify different sites for different IPs.

Looking at your configuration you are indicating 192.168 addresses for your remote services. 192.168 addresses are not public, these are LAN only IPs. Your droplet’s public address will not look like this.