Virtual host document root doesn't work - apache2

I created an A record for my subdomain.example.com which points x.x.x.x.
So my subdomain points the x.x.x.x IP address.
Also I want my subdomain to point a sub-directory. So, on x.x.x.x, I added these lines to httpd.vhosts.conf. This machine runs on xampp.
<VirtualHost *:80>
DocumentRoot /opt/lampp/htdocs/subdomain
ServerName subdomain.example.com
<Directory /opt/lampp/htdocs/subdomain>
allow from all
Options +Indexes
</Directory>
</VirtualHost>
But subdomain.example.com points x.x.x.x not x.x.x.x/subdomain. I don't understand what I'm doing wrong?

http://httpd.apache.org/docs/2.1/sections.html#mergin
Due to the merging order, some of the directives may override others. I found that <location> directive didn't let my <virtualhost> work properly.

Related

What is the meaning of star in <VirtualHost *:80> in apache?

I want to know the use of this * and how to configure it?
* means a wildcard when you use wildcard you do bifurcation on ServerName
<VirtualHost *:80>
DocumentRoot /var/www/app1
ServerName app1.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.com
</VirtualHost>
Apache will route example.com to /var/www/example where as app1.example.com would be routed to /var/www/app1
VirtualHost directive allows you to configure and use multiple sites located on the same IP address. In this case, with *:80 you are creating a virtual host for every request coming on the port 80. It becomes more interesting when you start specializing and start to insert something other than * in the virtual host. An example can be, that according to the IP address with which a port is hit, you can open a different version of a web site, perhaps with different resources like: language translations, styles etc.

Apache2 isolate virtualhosts

I'd like to isolate each "www subdirectory" so mysite1.ext can't access to mysite2.ext files, is this possible? How can I do it?
you Must conf You virtualHost Apache for this
like This
<VirtualHost x.x.x.x:80>
ServeName www.example.com
DocumentRoot /path/to/your/virtualroot
...
... usual stuff ...
...
php_admin_value open_basedir /path/to/your/virtualroot:/some/other/path
</VirtualHost>
Last Line Is For Isolate PHP To Access Other Directory
To do what you want in Apache you would use Name Based VirtualHosts. This allows you to configure two or more separate Web server environments on one IP address. It would look something like this.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.mysite1.ext
ServerAlias domain.ext *.domain.ext
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.mysite2.ext
DocumentRoot /www/otherdomain
</VirtualHost>
You can read more about this configuration here This would all go in Sites.enabled or http.conf depending on your end stage configuration.

Virtual Host don't redirect properly with CakePHP and MAMP

I'm developing a web with cakePHP (using MAMP as localhost) and I just configured a virtual hosts to the root of my project.
My /etc/hosts is
127.0.0.1 localhost
127.0.0.1 altair.loc
And my httpd.conf
NameVirtualHost *
<VirtualHost *>
DocumentRoot "/Volumes/Macintosh HD/Users/robotThree/www/"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "/Volumes/Macintosh HD/Users/robotThree/www/ALTAIR/altair/"
ServerName altair.loc
</VirtualHost>
With this I can access to my project typing http://altair.loc and all controllers and actions works perfectly (i.e. http://altair.loc/controller/action).
The problem is that all files accessed statically fails. For example http://altair.loc/css/main.css fails, but it works if I type http://altair.loc/ALTAIR/altair/css/main.css, as if the virtual host wasn't configured.
Do you know what could be happening?
Thank you in advance
Solved. In httpd.conf is necessary to check that Override is for all, it was an .htaccess and mod_rewrite issue:
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
</Directory>

Apache2 serving multiple sites on one IP

I have two domains that point to the same IP, which is an Ubuntu VPS with apache2. I need to server both domains out of apache. I've read the config manual at http://httpd.apache.org/docs/2.0/vhosts/examples.html#purename and added the following two files:
1) webikenconsultants
<VirtualHost *:80>
ServerName www.webikenconsultants.com
DocumentRoot /var/www/coming_soon
<Directory /var/www/coming_soon>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
2) webikentrading
<VirtualHost *:80>
ServerName www.webikentrading.net
#WSGIScriptAlias / /opt/webikentrading/current/src/webikentrading/django.wsgi
DocumentRoot /var/www
<Directory /var/www >
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
As you can see, webikentrading is a Django project, but for the time being, just to get things working, I am serving it as a static site, until I figure out what's going on. The problem is that when I visit either domain, only the coming_soon content shows up, what am I doing wrong??
I figured out the problem. The vhost entry points to www.webikentrading.net however, the browser was using webikentrading.net so i added a separate entry for just webikentrading.net and all is fine
EDIT:
This is quite old, but I have a new and improved way of doing this now and I hope it can help someone else.
Use the mod_wsgi daemon directive which allows you to add the python path of your choice. Example config is:
<VirtualHost *:80>
ServerName qa.webiken.net
....
WSGIDaemonProcess qa.webiken.net processes=2 threads=15 python-path=/usr/local/pythonenv/QA-WEBIKEN-1/lib/python2.5/site-packages display-name=%{GROUP}
WSGIProcessGroup qa.webiken.net
</VirtualHost>
<VirtualHost *:80>
ServerName staging.webiken.net
....
WSGIDaemonProcess staging.webiken.net processes=2 threads=15 python-path=/usr/local/pythonenv/staging-WEBIKEN-1/lib/python2.5/site-packages display-name=%{GROUP}
WSGIProcessGroup staging.webiken.net
</VirtualHost>

Does Apache2 support virtual hosting of subdomains?

Currently my Apache server is set up like so
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www
</VirtualHost>
The problem is that everything below /var/www is accessible from everywhere else. If I have a web page /var/www/john/bio.html, then that web page could borrow scripts/pictures from var/www/jane/
I want to set up my Apache server like so
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www
</VirtualHost>
<VirtualHost *:80>
ServerName www.john.example.com
ServerAlias john.example.com
DocumentRoot /var/www/john
</VirtualHost>
<VirtualHost *:80>
ServerName www.jane.example.com
ServerAlias jane.example.com
DocumentRoot /var/www/jane
</VirtualHost>
So all the files for user john go in the /var/www/john/ folder, and likewise for user jane. Then, with symbolic links turned off (by default), and access only provided from /var/www/user/ downwards (again by default), I don't have to worry about john's web page including scripts/images from jane's web page.
Using local measures only (/etc/hosts instead of a DNS) I found that this can indeed work.
First, change your /etc/hosts file to have a mapping of your desired website name(s) (www.example.com), and target IP address (192.168.1.1). I used my local IP address.
IPAddress Hostname Alias
----------- -------------------------- ------------------
192.168.1.1 www.example.com example.com
192.168.1.1 www.john.example.com john.example.com
192.168.1.1 www.jane.example.com jane.example.com
Your web browser will check your /etc/hosts file before looking at the world wide web.
Next go through all your Apache config files (httpd.conf, apache2.conf, ports.conf, conf.d/*) and make sure in exactly one file the command NameVirtualHost *:80 is issued (it doesn't have to be port :80 but if it is issued more than once, you will get this problem). Mine was issued in /etc/apache2/ports.conf, so put yours there if you have to. Finally, update your Apache configuration file (mine was at /etc/apache2/sites-available/default) like so.
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www
</VirtualHost>
<VirtualHost *:80>
ServerName www.john.example.com
ServerAlias john.example.com
DocumentRoot /var/www/john
</VirtualHost>
<VirtualHost *:80>
ServerName www.jane.example.com
ServerAlias jane.example.com
DocumentRoot /var/www/jane
</VirtualHost>
As a final step, you may need to add the websites to Apache by issuing the below commands (this step is not necessary, if you give all websites into sites-available/default and not into separate files for individual websites).
# a2ensite www.example.com
# a2ensite www.john.example.com
# a2ensite www.jane.example.com
After doing this, john.example.com will go to /var/www/john. That directory will then act as the root directory, and john will no longer have access to www, and, therefore, have no access to /var/www/jane.
Likewise, after doing this, jane.example.com will go to /var/www/jane. That directory will then act as the root directory, and jane will no longer have access to www, and, therefore, have no access to /var/www/john.
With symbolic links turned off --by default-- neither directories will be able to access each other

Resources