Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache virtual host without domain name

Tags:

I have a VPS with apache2 installed and I would like to access some PHP projects without a domain name just with the IP address. For example:

http://162.243.93.216/projecta/index.php http://162.243.93.216/projectb/index.php 

I have other projects with domain like example.com, in my directory /var/www/

/html/    info.php /projecta/ /projectb/ /example/ 

When I go to

http://162.243.93.216/info.php then /var/www/html/info.php is opened.  

My file 000-default.conf

<VirtualHost *:80>     ServerAdmin webmaster@localhost     DocumentRoot /var/www/html      <Directory /var/www/>             Options Indexes FollowSymLinks MultiViews             AllowOverride All             Order allow,deny             allow from all      </Directory>      ErrorLog ${APACHE_LOG_DIR}/error.log     CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 
like image 485
heychez Avatar asked Nov 03 '14 02:11

heychez


People also ask

Can a browser make a request to a server without a domain name?

You sure can! It might or might not be as convenient but you surely can. You can spin up a local/remote web-server and deploy the website to that place. However if you want to put it to good use, a domain is pretty much a must; It's more of a marketing/usability thing then it's actually required.

What are the types of virtual hosts in Apache?

There are two types of virtual hosts on Apache: IP-Based Virtual Hosting – every individual website on the Apache Server uses a different, unique IP address. Name-Based Virtual Hosts – enables you to add multiple domains using a single IP address.


1 Answers

" http://162.243.93.216/info.php then /var/www/html/info.php is opened " 

I am assuming this already works (If not, uncomment the ServerAlias line shown in the conf below)

You now want to map

http://162.243.93.216/projecta/ to /var/www/projecta
http://162.243.93.216/projectb/ to /var/www/projectb

For this you need to use the Apache Alias directive.

Update your 000-default.conf file to:

<VirtualHost *:80>     # ServerAlias 162.243.93.216     ServerAdmin webmaster@localhost     DocumentRoot /var/www/html      Alias /projecta /var/www/projecta     Alias /projectb /var/www/projectb      <Directory /var/www/>             Options Indexes FollowSymLinks MultiViews             AllowOverride All             Order allow,deny             allow from all      </Directory>      ErrorLog ${APACHE_LOG_DIR}/error.log     CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> 
like image 114
kums Avatar answered Oct 02 '22 12:10

kums