I have the following vhosts setup:
<VirtualHost *:80>
ServerAdmin admin#localhost.com
DocumentRoot "C:\Apache24\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost cake-photos.com:80>
ServerAdmin admin#localhost.com
DocumentRoot "C:\Apache24\htdocs\cake-photos"
ServerName cake-photos.com
ServerAlias *.cake-photos.com
<Directory "C:\Apache24\htdocs\cake-photos">
Options Indexes FollowSymLinks
AllowOverride all
Require ip 127.0.0.1
</Directory>
</VirtualHost>
<VirtualHost fangwear.co.uk:80>
ServerAdmin admin#localhost.com
DocumentRoot "C:\Apache24\htdocs\Fangwear 2014"
ServerName fangwear.co.uk
ServerAlias www.fangwear.co.uk
<Directory "C:\Apache24\htdocs\Fangwear 2014">
Options Indexes FollowSymLinks
AllowOverride all
# Require all granted
Require ip 127.0.0.1
</Directory>
</VirtualHost>
<VirtualHost manager.com:80>
ServerAdmin admin#localhost.com
DocumentRoot "C:\Apache24\htdocs\Manager 2014"
ServerName manager.com
ServerAlias www.manager.com
<Directory "C:\Apache24\htdocs\Manager 2014">
Options Indexes FollowSymLinks
AllowOverride all
# Require all granted
Require ip 127.0.0.1
</Directory>
</VirtualHost>
None of it seems to be working and if I try to go to any of these I end up being redirected to the cake-photos.com vhost.
I need to be able to get to other things too such as localhost/phpmyadmin but that won't work with this configuration.
Where am I going wrong?
Did you set up your hosts file? On Unix Systems /etc/hosts? And did you restart your server?
Related
I have a set up as follows:
All subdomains pointing to the server
sub1.example.com should load /var/www/sub1
sub2.example.com should load /var/www/sub2
Any random subdomain should load /var/www/shared
The problem is the shared.conf file is being ignored and instead using sub1 (or whichever one I move to the start of the .conf file list).
Here are my conf files in their order after running ls -lv
sub1.conf
sub2.conf
shared.conf
sub1.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName sub1.example.com
ServerAlias sub1.example.com
<Directory /var/www/sub1/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/sub1
</VirtualHost>
sub2.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName sub2.example.com
ServerAlias sub2.example.com
<Directory /var/www/sub2/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/sub2
</VirtualHost>
shared.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerAlias *.example.com
<Directory /var/www/shared/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/shared
</VirtualHost>
I have also tried adding a random subdomain to the shared.conf file for Server Name, i.e.
ServerName shared-random.example.com
And also
ServerName *.example.com
I have also made sure to restart apache.
So when I put in any subdomain, e.g. blabla.example.com it always goes to sub1.conf.
I understand that the behaviour is to default to the first one, but only if there isnt a match. Why isnt shared.conf being considered a match?
change filename from shared.conf to 000-shared.conf
use below config for 000-shared.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/shared
<Directory /var/www/shared>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
</VirtualHost>
i have a problem with apache2 on localhost
i have many virtualhost and thats worked fine before, but today i have a problem
when i try open test-bot.app apache force me to https://test-web.app!
this is my vhost file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName test-bot.app
ServerAlias test-bot.app
DocumentRoot /var/www/html/test-bot/public
<Directory />
AllowOverride All
</Directory>
<Directory /var/www/html/test-bot/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
ErrorLog /var/log/apache2/test-bot.app-error.log
LogLevel error
CustomLog /var/log/apache2/test-bot.app-access.log combined
</VirtualHost>
what can i do?
<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
I have this configuration but both url app.test.com & stage.test.com
redirect to same code/deployment
<VirtualHost *:80>
ServerName app.test.com
DocumentRoot /var/www/html/Test-Prod/web
<Directory "/var/www/html/Test-Prod/web">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog logs/test-prod__error_log
CustomLog logs/test-prod_access_log common
</VirtualHost>
<VirtualHost *:80>
ServerName stage.test.com
DocumentRoot /var/www/html/Test/web
<Directory "/var/www/html/Test/web">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
ErrorLog logs/test-website_error_log
CustomLog logs/test-website_access_log common
</VirtualHost>
The usual error for this is leaving out the NameVirtualHost directive if you're still using httpd 2.2
Add the following in your config file and it'll probably work
NameVirtualHost *.80
You might want to read the documentation for Named-based Virtual Host Support with httpd 2.2.
NameVirtualHost *.80
<VirtualHost localhost:80>
ServerName color
ServerAlias localhost
ServerPath "C:/wamp/www/subwww/color"
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www/subwww/color">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
in above code, subdomain name is color
and the url is http://color.localhost/
if the operating system is windows then add "127.0.0.1 color.localhost" in "C:/windows/system32/dirvers/etc/hosts" with notepad run as administration
I've configured two virtual host cuckoo.net and fb.core.net are located to local ip address (127.0.0.1)
But when I access the second domain: fb.core.net, it always returns the first.
Please consider the below configuration to help me, I really don't know what I am wrong here.
<VirtualHost *:80>
DocumentRoot "d:/_iLearning/iCuckoo"
ServerName cuckoo.net
ServerAlias www.cuckoo.net
SetEnv APPLICATION_ENV "development"
<Directory d:/_iLearning/iCuckoo>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "d:/_Devs/fbcore/public"
ServerName fb.core.net
ServerAlias www.fb.core.net
SetEnv APPLICATION_ENV "development"
<Directory d:/_Devs/fbcore/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Add fb.core.net to the ServerAlias
<VirtualHost *:80>
DocumentRoot "d:/_Devs/fbcore/public"
ServerName fb.core.net
ServerAlias www.fb.core.net fb.core.net # you can add more than one here
SetEnv APPLICATION_ENV "development"
<Directory d:/_Devs/fbcore/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
i face this issue today
please check this url
http://alexking.org/blog/2007/11/01/apache-2-only-serves-first-virtual-host
my config i add
NameVirtualHost *
i think you need to add
NameVirtualHost *:80
or change
<VirtualHost *:80>
to
<VirtualHost *>
My config
NameVirtualHost *
<VirtualHost *>
DocumentRoot /home/host1/www
ServerName host1.bdwey.com
ServerAlias www.host1.bdwey.com
<Directory "/home/host1/www">
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot /home/host2/www
ServerName host2.bdwey.com
ServerAlias www.host2.bdwey.com
<Directory "/home/host2/www">
allow from all
Options +Indexes
</Directory>
</VirtualHost>