I have two websites www.test1.com and www.test2.com.I hosted both sites in windows wampp server with same IP called xx.xxx.xx.xx .But while opening both sites www.test1.com is comming.Here www.test1.com files are in 'test1' folder and www.test2.com are in 'test2' folder.
I Tried virtual host in wampp...but its not working...
This is my \wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf file
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/test1"
ServerName test1
ServerAlias test1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/test2"
ServerName localhost
ServerAlias test2.com
<Directory "c:/wamp/www/test2">
AllowOverride All
Require local
Require all granted
Allow from all
</Directory>
</VirtualHost>
This is my C:\Windows\System32\drivers\etc\hosts file
127.0.0.1 localhost
127.0.0.1 test1.com
127.0.0.1 test2.com
Both your domain names are going to the site defined first in the httpd-vhost.conf file because that is the default behaviour when Apache cannot find a site requested in the host definitions. It normally means you have done something wrong in the defining of your VHOSTS.
Your host definitions are a little wrong, and you are mixing Apache 2.2 and 2.4 security syntax which often causes problems, try these
# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
DocumentRoot "C:/wamp/www"
ServerName localhost
<Directory "C:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/test1"
ServerName test1.com
ServerAlias www.test1.com
<Directory "c:/wamp/www/test1">
AllowOverride All
Require local
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/test2"
ServerName test2.com
ServerAlias www.test2.com
<Directory "c:/wamp/www/test2">
AllowOverride All
Require local
Require all granted
</Directory>
</VirtualHost>
Now so that you can see the sites locally on the WAMPServer PC the hosts file should look like this. Remember, these entries only effect the PC containing the HOSTS file, and have no effect on internet access or the ability of a remote user to use these domain name.
# IPV4 loopback
127.0.0.1 localhost
127.0.0.1 test1.com
127.0.0.1 test2.com
# IPV6 loopback
::1 localhost
::1 test1.com
::1 test2.com
The first line needs to be
NameVirtualHost *:80
Related
I have installed Laravel Project with all its dependencies. Also, Setup Virtual Hosts for the same. But, When I hit the url like say "dev.laravelProject.com" it immediately opening Xampp Dashboard.
I don't know why is that happened.
Any Help Appreciated
First, change your /etc/hosts file to have a mapping of your desired website name(s) (www.example.com), and target IP address (127.0.0.1). I used my local IP address.
IPAddress Hostname Alias
----------- -------------------------- ------------------
127.0.0.1 www.librarymodule.com librarymodule.com
127.0.0.1 www.dev.librarymodule.com dev.librarymodule.com
So, you can set only one domain
<VirtualHost *:80>
DocumentRoot "/var/www/html/LibraryProject/public"
ServerName librarymodule.com
ServerAlias *.librarymodule.com
<Directory "/var/www/html/LibraryProject/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
or add first the main one and then the subdomain:
<VirtualHost *:80>
DocumentRoot "/var/www/html/LibraryProject/public"
ServerName www.librarymodule.com
ServerAlias librarymodule.com
</VirtualHost>
<VirtualHost *:80>
ServerName www.dev.librarymodule.com
ServerAlias dev.librarymodule.com
DocumentRoot "/var/www/html/LibraryProject/public"
</VirtualHost>
As a final step, you may need to add the websites to Apache by issuing the below commands:
# a2ensite librarymodule.com
# a2ensite dev.librarymodule.com
- Reload apache.
I am trying to create sub-domains on my localhost to be accessed concurrently by my team but only the first project is loaded even when the url for the second domain is typed in the browser.
So far I have tried changing the httpd-vhosts.conf file
<VirtualHost *:80>
ServerAdmin webmaster#smartsacco.localhost.com
DocumentRoot "C:/xampp/htdocs/smartsacco/public"
ServerName smartsacco.localhost.com
ErrorLog "logs/smartsacco.localhost.com-error.log"
CustomLog "logs/smartsacco.localhost.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#mfarmer.localhost.com
DocumentRoot "C:/xampp/htdocs/Mfarmer/public"
ServerName mfarmer.localhost.com
ErrorLog "logs/mfarmer.localhost.com-error.log"
CustomLog "logs/mfarmer.localhost.com-access.log" common
</VirtualHost>
And also modified the hosts file
127.0.0.1 localhost
::1 localhost
127.0.0.1 smartsacco.localhost.com
127.0.0.1 mfarmer.localhost.com
Saddly only the contents of smartsacco.localhost.com is loaded even when I type mfarmer.localhost.com. What could Be wrong or and what can I do to have them both working?
Since your code is correct, I suggest you restart Apache server and maybe the entire computer
i bought VPS and i installed 3 websites. All websites are loading files from one directory( but i set the different while i was creating ).
After putting DNS without making Virtual Hosts, site already loads default web site(first one), after creating virtual host, still the same.
<VirtualHost *>
DocumentRoot /home/svezatebe-online.com/www/
ServerName svezatebe-online.com
<Directory "/home/svezatebe-online.com/www/">
allow from all
Options FollowSymLinks
</Directory>
ServerAlias www.svezatebe-online.com
</VirtualHost>
<VirtualHost *>
ServerName wasdlife.com
<Directory /home/wasdlife.com/www>
allow from all
Options None
</Directory>
ServerAlias www.wasdlife.com
</VirtualHost>
<VirtualHost *>
DocumentRoot /home/online-vesti.net/www
ServerName online-vesti.net
<Directory "/home/online-vesti.net/www">
allow from all
Options None
</Directory>
</VirtualHost>
I would consider some examples from: https://httpd.apache.org/docs/2.4/vhosts/examples.html especialy try to adjust your config according to example below:
# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
DocumentRoot "/www/example1"
ServerName www.example.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/www/example2"
ServerName www.example.org
# Other directives here
</VirtualHost>
For testing you can try to do a quick changes in your hosts file to try localy instead of having to do a DNS changes like mentioned at the link above:
Creating virtual host configurations on your Apache server does not
magically cause DNS entries to be created for those host names. You
must have the names in DNS, resolving to your IP address, or nobody
else will be able to see your web site. You can put entries in your
hosts file for local testing, but that will work only from the machine
with those hosts entries.
i am trying to add another local domain to my mac osx:
No matter what i do when visiting say 'domainnumber2.dev' it always displays the first host in my list.
If i swop them around in my httpd-vhosts file then i get the domainnumber2.dev site.
How can i run multiple localhost site on my mac.
I have a simple set up as below:
<VirtualHost *:80>
ServerName mydomain.dev
ServerAlias mydomain.dev
DocumentRoot "/Users/UserName/Sites/mydomain/"
</VirtualHost>
<VirtualHost *:80>
ServerName mydomainTwo.dev
ServerAlias mydomainTwo.dev
DocumentRoot "/Users/UserName/Sites/mydomainTwo/"
</VirtualHost>
I have also had the more details set up adding the below for both
<Directory "/Users/UserName/Sites/mydomain/">
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
In my hosts file i have:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 mydomain.dev
127.0.0.1 mydomainTwo.dev
which ever VirtualHost is first is the site that is served up
I stumbled across this same problem...
In your httpd-vhosts.conf file (/private/etc/apache2/extra/httpd-vhosts.conf after showing hidden files) add the following for each domain...
<VirtualHost *:80>
ServerName mysubdomain.dev
CustomLog "/root/to/site/logs/mysubdomain.dev-access_log" combined
ErrorLog "/root/to/site/logs/mysubdomain.dev-error_log"
DocumentRoot "/root/to/site/mysubdomain.co.uk"
<Directory "/root/to/site/mysubdomain.co.uk">
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Then restart apache. Everything else you have seems to be the same as my setup.
Make sure you have the correct permissions to be able to write the log files etc too.
I have vhost like this:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName local.testing.com
DocumentRoot "/Users/myname/Sites/myapp"
DirectoryIndex index.html
<Directory /Users/myname/Sites/myapp>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow From All
</Directory>
</VirtualHost>
hots files
127.0.0.1 localhost
127.0.0.1 local.testing.com
::1 localhost
after enabling this vhost , i am unable to access any of the sites under xampp/htdocs through http. But they are accessible through https
when I access localhost it shows directory listing for :"/Users/myname/Sites"
plz help me sort out this issue ,
thanks in advance
so the issue was that we need a virtual host for localhost e. g like this SOQ
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
ServerAlias localhost
ServerName localhost
</VirtualHost>