Multiple Virtual Hosts not working - apache

I am trying to set up two virtual hosts for one IP address say xxx.yy.xxx.yyy
I have my files on /var/www/html/folder1 and /var/www/html/folder2
I am adding VH like :
DocumentRoot /var/www/html/folder1
ServerName xxx.yy.xxx.yyy/folder1
AllowOverride All
DocumentRoot /var/www/html/folder12
ServerName xxx.yy.xxx.yyy/folder2
AllowOverride All
As I am new on CentOS7 Apache, can't figure out how to solve it.

I do not know if I can be helpful but I locally configure so apace to have multiple domains
<VirtualHost q4y.aurecchia.dev:80>
DocumentRoot "C:\xampp\htdocs\QuestManager\AurQuest4You\public"
ServerAdmin q4y.aurecchia.dev
<Directory "C:\xampp\htdocs\QuestManager\AurQuest4You">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost csm.aurecchia.loc:80>
DocumentRoot "C:\xampp\htdocs\CSM TEST\Aur_CSM\public"
ServerAdmin csm.aurecchia.loc
<Directory "C:\xampp\htdocs\CSM TEST\Aur_CSM">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Related

XAMPP can't see virtual host

I am trying to create virtual host with xampp but it seems my apache configuration can't read host I created.
Every single time when I'm going to moodle36.dev/moodle/install.php in my browser it's reading xampp/htdocs/moodle instead of moodle from vhosts
That's my htttpd-vhosts.conf
NameVirtualHost *80
...
<VirtualHost *:80>
DocumentRoot "C:/xampp/vhosts/moodle36.devel"
ServerName moodle36.dev
ServerAlias www.moodle36.dev
<Directory "C:/xampp/vhosts/moodle36.devel">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
That's httpd.conf
<Directory />
AllowOverride all
Allow from all
</Directory>
DocumentRoot "C:/xampp/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride All
Allow from all
</Directory>
<Directory "C:/xampp/htdocs">
...
</Directory/>
I uncomented
Include conf/extra/httpd-vhosts.conf
and System32/drivers/etc/hosts
127.0.0.1 moodle36.dev
I'm completly stuck and i would apreciatte any kind of help.
It might be because .dev is an existing top level domain.
Try .localhost or something that isn't in this list:
https://www.icann.org/resources/pages/tlds-2012-02-25-en

Apache2 subdomain redirects to main domain

I have an EC2 instance setup running Ubuntu 14.04 and Apache. I have a single elastic IP serving multiple domains and subdomains all of which point to individual folders on the server. The problem I am having is unless the subdomain is explicitly set in my .conf it will redirect to the main domain. I can't seem to find a definitive answer here or in google.
I have a single .conf file residing in /etc/apache2/sites-enabled/ serving all of the domains and subdomains like so:
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html/mydomain.com
<Directory /var/www/html/mydomain.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName sub1.mydomian.com
ServerAlias www.sub1.mydomain.com
DocumentRoot /var/www/html/sub1.com
<Directory /var/www/html/sub1.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName sub2.mydomian.com
ServerAlias www.sub2.mydomain.com
DocumentRoot /var/www/html/sub2.com
<Directory /var/www/html/sub2.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName mydomain2.com
ServerAlias www.mydomain2.com
DocumentRoot /var/www/html/mydomain2.com
<Directory /var/www/html/mydomain2.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
So if I go to sub1.mydomain.com or sub2.mydomain.com it gets properly routed. But if I type sub3.mydomain.com which does not exist in my .conf file it gets redirected to mydomain.com. I do not want this behavior. How do I resolve this?
You need to enable name based virtualhosts. Add below line before your first virtual host and restart apache.
NameVirtualHost :80

virtual host setup in xampp, won7

I install XAMPP(OS : win 7 ) in D drive. Document root is D:/xampp/htdocs
When I open localhost/xampp/ then it open . No problem
I create virtual host zf2.local as bellow and it's working fine.
<VirtualHost zf2.local:80>
ServerAdmin webmaster#localhost
DocumentRoot "D:/xampp/htdocs/WORK/zend/public"
ServerName zf2.local
</VirtualHost>
But when I configure like bellow then it's show forbiden
<VirtualHost zf2.local:80>
ServerAdmin webmaster#localhost
DocumentRoot "D:/WORK/zend/public"
ServerName zf2.local
</VirtualHost>
Actually I want to set document root outside the htdocs & both should work means localhost as well as virtual host. please help me.
<VirtualHost *>
ServerAdmin admin#localhost.com
DocumentRoot "C:/xampp/htdocs" # change this line with your htdocs folder
ServerName localhost
ServerAlias localhost
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Read this article for further help
This should solve your problem:
<Directory "D:/WORK/zend/public">
Options Indexes FollowSymLinks Includes ExecCGI
Order allow,deny
Allow from all
Require all granted
</Directory>
OR
<Directory "D:/WORK/zend/public">
Allow from all
Require all granted
</Directory>

XAMPP Windows Apache vhosts not redirecting properly

<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
<Directory "C:/xampp/htdocs/">
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/gl"
ServerName gl.dev
<Directory "C:/xampp/htdocs/gl">
Order allow,deny
allow from all
</Directory>
</VirtualHost>
The above is what I currently have in my vhosts file. When I hit localhost I want my root to open, but when I load gl.dev I want the individual site to open. Any ideas?
hosts file:
127.0.0.1 localhost
# ::1 localhost
127.0.0.1 gl.dev
I think in windows you have to use backslash when specifying document root. please try the following
<VirtualHost *:80>
ServerName localhost
ServerAlias *.localhost
DocumentRoot "C:\xampp\htdocs\"
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName gl.dev
ServerAlias *.gl.dev
DocumentRoot "C:\xampp\htdocs\gl"
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Restart WAMP server

2 domains pointing to 1 server (2 different subfolders)

OK, so, I think the title is rather self-explanatory.
I've set up my own Apache server (on Debian) and hosting 2 different sites (let's say mysite1.com at /home/www/mysite1, and mysite2.com at /home/www/mysite2).
In my domain name registrar setup page (Dynadot actually), I created A records (still not sure what this is exactly...) for both of them, pointing to my server's ip...
Now, on the server's side, here'e what my .conf file looks like (/etc/apache2/sites-enabled/mysite actually)
<VirtualHost *:80>
DocumentRoot /home/www/mysite1.com
ServerName www.mysite1.com
ServerAdmin drkameleon#gmail.com
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/www/mysite1.com>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin
<Directory "/home/www/mysite1.com/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot /home/www/phpmyadmin
ServerName www.mysite1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/www/mysite2.com
ServerName www.mysite2.com
ServerAdmin drkameleon#gmail.com
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/www/mysite2.com>
Options Indexes FollowSymLinks Multiviews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Now, the thing is. Now matter which site I visit (1 or 2), I always get mysite1's contents.
What am I doing wrong? Any ideas?
There are multiple possibilities of what could go wrong.
Do you have
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
somewhere in the config? (http://httpd.apache.org/docs/2.2/mod/core.html#namevirtualhost)
Without that config entry Apache is not sensitive to domain names in dispatching requests to virtual hosts.
It's just a guess.
Make sure Apache has been reloaded after any changes to the config!