Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache virtualhosts: different paths serve different application on same IP

I have setup on my local network an Ubuntu server with Apache2 on it.

I would like to manage different applications on the same server, when you request an url a dedicated application is served.

E.g.

http://192.168.0.25/my_app_1 -> responds with app1 (for example a Ruby on Rails app)
http://192.168.0.25/my_app_2 -> responds with app2 (for example a php website)
[...]
# where 192.168.0.25 is the IP of the server

I think that this is done by configuring correctly the virtualhosts in Apache2.

At this moment, a sample configuration of app1 (i.e. Ruby on Rails) is like the followed:

<VirtualHost 192.168.0.25:80>
 DocumentRoot path_to_my_public_app1_folder
 <Directory path_to_my_public_app1_folder>
  Options -MultiViews
  AllowOverride All
 </Directory>
 RailsEnv production
</VirtualHost>

How can define the sub path? Maybe something like this?

<VirtualHost 192.168.0.25/my_app1:80>

Am I doing it right? Because at this moment I recieve a 404 (not even the custom Apache page "It's work!")

like image 908
damoiser Avatar asked Sep 30 '13 09:09

damoiser


People also ask

What is the benefit of Apache virtual hosting?

The Apache HTTP Server's built in virtual hosting allows the server to provide different information based on which IP address, hostname, or port is being requested. A complete guide to using virtual hosts is available online at http://httpd.apache.org/docs-2.0/vhosts/.

What can be used to differentiate one VirtualHost from another?

IP-based virtual hosts use the IP address of the connection to determine the correct virtual host to serve. Therefore you need to have a separate IP address for each host.

How does Apache VirtualHost work?

The Apache HTTP server supports virtual hosts, meaning that it can respond to requests that are directed to multiple IP addresses or host names that correspond to the same host machine. You can configure each virtual host to provide different content and to behave differently.


1 Answers

VirtualHost means something different. It allows you (in short) to host sites responding to different names, e.g.:

http://mydomain.com
http://anotherdomain.com

on the same server. So think of it as virtual appaches, all on the same machine, but identified by different names.

Your usecase is different. You want to configure the instance 192.168.0.25 and how it serves different requests. So the part after the host in the URL: http://HOST/PATH_TO_APP

For the instance responding to 192.168.0.25 you should edit the default config in

/etc/apache2/sites-available/default

You can add the following:

Alias /my_app_1 path_to_my_public_app1_folder
Alias /my_app_2 path_to_my_public_app2_folder
like image 194
Scolytus Avatar answered Sep 30 '22 13:09

Scolytus