Multiple versions of a website each with its own root directory using Apache - apache

I have multiple versions of my website. Each resides in its own folder, for example:
site_v1/
index.html
page1.html
site_v2/
index.html
page1.html
How can I configure apache so that each version of the site has its own definition of the root directory?
In other words, I want site_v1/index.html to think the root directory is site_v1, and site_v2/index.html to think the root directory is site_v2

You are looking for the VirtualHost directive.
Apache manual on virtual hosts

As #Pekka wrote, you are indeed looking for the VirtualHost directive, but I though I might add an example configuration for your virtual host configuration. This should be placed in your httpd.conf file, edited to your preference, and remember to fill in the full path:
NameVirtualHost v1.yoursite.com:80
<VirtualHost v1.yoursite.com:80>
ServerName v1.yoursite.com
ServerAlias v1.yoursite.com
DocumentRoot /path/to/site_v1
ErrorLog /path/to/prefered/error.log
CustomLog /path/to/prefered/access.log combined
<Directory /path/to/site_v1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost v2.yoursite.com:80
<VirtualHost v2.yoursite.com:80>
ServerName v2.yoursite.com
ServerAlias v2.yoursite.com
DocumentRoot /path/to/site_v2
ErrorLog /path/to/prefered/error.log
CustomLog /path/to/prefered/access.log combined
<Directory /path/to/site_v2>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If you want, you may chose to use a different access/error log for each version of your site. Just change the name/path to the log file, and you're done. /path/to are the path to the site folder, and v1.yoursite.com & v2.yoursite.com should be changed to the relative domains you want to use for each version. If you don't want to change the log files, remove the ErrorLog and CustomLog directives and I'll default to the main log files set in httpd.conf

Related

Make all subdomains point to on single file/folder using ".conf" file

I wanted to redirect all my subdomain to a single file/folder I done the pointing thing before using .conf files in apache but I did it for a specific domain.
this is the conf file that I use for pointing the domain.
listen 80
<VirtualHost *:80>
ServerName subdomain.domain.com
DocumentRoot /var/www/html/project/dist
<Directory /var/www/html/project/dist>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
but what I want is to redirect all the subdomain to redirect to the same project which has some domain for example:-
currently, the upper conf file will redirect to my project folder but what I want is that if I have domain-like
sd1.domain.com
sd2.domain.com
sd3.domain.com
they should also point to the same project directory. but I am not sure how to do it
thx in advance
I solved my problem by doing a slight change into my .conf file here is my new file
listen 80
<VirtualHost *:80>
ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/html/project/dist
<Directory /var/www/html/project/dist>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
what I did I add the server alias to (*) which let me allow to redirect all my subdomain to single project.

Virtual host not displaying correct files

Centos 7.1 and apache 2.4 - We have installed a new drive in our server and want to move all of our sites to that drive (mounted as /data) and sites are located in /data/vhosts
When trying to access the site we are presented with the apache welcome screen. I can confirm that the vhost is loaded as trying changing the permissions of the dir above results in a forbidden access. There is also an index.php file located in /data/vhosts/test.mydomain.com/public_html
# IP has been changed for example:
<VirtualHost 91.91.91.91:80>
DocumentRoot "/data/vhosts/test.mydomain.com/public_html"
ServerName test.mydomain.com
<Directory /data/vhosts/test.mydomain.com>
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
</VirtualHost>
UPDATE 1:
I have deleted the welcome.conf file in /etc/httpd/conf.d/ and I am not given a forbidden 403. It is important to note that this is a new drive and no permissions has been set on /data (or sub folders) for apache. I am not entirely sure if that makes a difference?
I have also made some slight alternations to the vhost conf file but no difference:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/data/vhosts/test.mydomain.com/public_html"
ServerName test.mydomain.com
<Directory "/data/vhosts/test.mydomain.com">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<Directory /data/vhosts/test.mydomain.com/public_html>
Options Indexes FollowSymLinks Includes ExecCGI
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Two sites with Apache virtual hosts

I'm working on 2 different sites. I have local copies of them checked out from SVN at my home folder, and symbolic links in /var/www pointing to them.
I've set up virtual hosts in httpd.conf like this:
<VirtualHost *:80>
DocumentRoot /var/www/siteA
ServerName 192.168.0.10/siteA
<Directory "/var/www/siteA">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/siteB
ServerName 192.168.0.10/siteB
<Directory "/var/www/siteB">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I would like to be able to access the sites with 192.168.0.10/siteA and /siteB, but when typing the address in browser, it throws a 404 and apache error log says: "File does not exist: /var/www/siteA/siteA".
What am I doing wrong and where does the second "/siteA" come from?
You've got too much configuration in there. /SiteA and /SiteB should be paths relative to your site root, you can't have different sites on the same host header, which in this case is "192.168.0.10". If you want to bind that address to the configuration, something along the lines of the following should work.
<VirtualHost 192.168.0.10:80>
DocumentRoot /var/www
ServerName 192.168.0.10
<Directory "/var/www">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If you now browse to /SiteA, /SiteB you should see the contents of your directory as long as your symlinks are correct. You also need to ensure you have the "NameVirtualHost" directive set correctly in your httpd.conf.

Redirect to a subfolder in Apache virtual host file

I have Joomla installed on a webserver running Ubuntu Server 12.04. The Joomla folder is located at /var/www/cms/.
My vhost file at /etc/apache2/sites-enabled/default has the following content:
<VirtualHost *:80>
ServerName domain.com/
Redirect permanent / https://domain.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName domain.com:443
DocumentRoot /var/www/cms
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/cms>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
(...)
</VirtualHost>
At the moment, all the requests to domain.com and anything entered after that like domain.com/example gets directed and processed by Joomla which either redirects to a proper page or returns a custom 404 error. This all works.
Now, I would like to filter all the requests that go to domain.com/subfolder before they get processed by Joomla and redirect them to /var/www/subfolder (instead of my root folder at /var/www/cms/).
I believe the file in /etc/apache2/sites-enabled/default (seen above) is the right place to define such a redirect, however I have not been able to figure out at what position and how to achieve this.
You should add to your configuration:
Alias /subfolder /var/www/subfolder
<Directory /var/www/subfolder>
Order allow,deny
allow from all
</Directory>
and fit the configuration between "Directory" to your needs.
See the Apache documentation to have more informations.

httpd.conf - Setting up a second "localhost" to a different localpath

I'm using XAMPP on my Windows 7 computer when doing web projects. In my httpd.conf file, DocumentRoot is set up simple, like this:
DocumentRoot "D:/Users/Thinkpad/DropBox/MAMP"
<Directory "D:/Users/Thinkpad/DropBox/MAMP">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
This location is used for work projects, and now I want a separate location just like this one, for private projects. Just have it to point to a different localpath, D:/Users/Thinkpad/DropBox/Web, and preferrably name it something other than localhost. Something like private or something. So my URL will end up looking like this http://private/mywebproject
I've tried looking at documentation for this, but I can't get it to work. Do I need to edit my hosts file for it to work? And what else needs to be set in httpd.conf file?
Edit: So here's the final solution from the httpd-vhosts file
<VirtualHost private:80>
DocumentRoot "D:/Users/Thinkpad/Dropbox/Web"
ServerName private
ErrorLog "logs/dropbox.local-error.log"
CustomLog "logs/dropbox.local-access.log" combined
<Directory "D:/Users/Thinkpad/Dropbox/Web">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost localhost:80>
DocumentRoot "D:/Users/Thinkpad/Dropbox/MAMP"
ServerName private
ErrorLog "logs/dropbox.local-error.log"
CustomLog "logs/dropbox.local-access.log" combined
<Directory "D:/Users/Thinkpad/Dropbox/MAMP">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
I had to add the regular localhost as well, even though it was already defined in httpd.conf file.
Also, hosts-file needed to have these two lines:
127.0.0.1 localhost
127.0.0.1 private
You have to add new virtual host
by default in C:\xampp\apache\conf\extra\httpd-vhosts.conf add something like
<VirtualHost *:80>
ServerName private.localhost
DocumentRoot D:/Users/Thinkpad/DropBox/private
</VirtualHost>
and after that you have to edit windows hosts file
append this
127.0.0.1 private.localhost
then restart the xammp
You may take a look to one project that makes this easy https://github.com/vkdimitrov/VhostsEditor