This is the changes made by me in httpd-vhosts.conf file
The code for the localhost
<VirtualHost *>
DocumentRoot "D:\xampp\htdocs"
ServerName localhost
</VirtualHost>
The code for my domain:
<VirtualHost *:800>
ServerAdmin postmaster#myshop.local
DocumentRoot "D:\ampp\htdocs\myshop.local\www"
ServerName myshop.local
ServerAlias www.myshop.local
<Directory "D:\xampp\htdocs\myshop.local">
Order allow,deny`enter code here`
Allow from all
</Directory>
</VirtualHost>
I need to use myshop.local instead of localhost!!!
So in hosts i did the following but still can't access it through any
browser:
127.0.0.1 localhost
127.0.0.1 myshop.local
127.0.0.1 www.myshop.local
Related
I have xampp with apache 2.4 on windows 10.
i have this configuration in my C:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
ServerAlias www.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/site3/web"
ServerName site3.localhost
ServerAlias www.site3.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/site2/web"
ServerName site2.localhost
ServerAlias www.site2.localhost
</VirtualHost>
I added in my hosts file:
127.0.0.1 site2.localhost
127.0.0.1 site3.localhost
127.0.0.1 www.site2.localhost
127.0.0.1 www.site3.localhost
When i browse http://site2.localhost i see xampp root index.
When i browse http://site3.localhost i see again xampp root index.Same with www.site2.localhost...
What am I doing wrong?
A quick bit of info on Virtual Hosts. If you set one up and when you try and use it it sends you to the first Virtual Host, normally localhost it means there is something wrong with the Virtual Host definition or the HOSTS file, or you have entered the url incorrectly.
Apache will use the first VH defined in the file as the default site.
First remove these 2 lines from the HOSTS file
127.0.0.1 www.site2.localhost
127.0.0.1 www.site3.localhost
The HOSTS file should look like this
127.0.0.1 localhost
127.0.0.1 site2.localhost
127.0.0.1 site3.localhost
::1 localhost
::1 site2.localhost
::1 site3.localhost
Now each Virtual Host definition should also include some access rights like this
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/site3/web"
ServerName site3.localhost
ServerAlias www.site3.localhost
<Directory "C:/xampp/htdocs/site3/web/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/site2/web"
ServerName site2.localhost
ServerAlias www.site2.localhost
<Directory "C:/xampp/htdocs/site2/web/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
I am hosting two domains on a vps server. The domains, let say www.abc.net(or abc.net) and www.xyz.net(or xyz.net) have following config
<VirtualHost *:80>
ServerName abc.net
ServerAlias www.abc.net
ServerAdmin webmaster#localhost
DocumentRoot /var/www/abc.net
ErrorLog ${APACHE_LOG_DIR}/abc.net.error.log
CustomLog ${APACHE_LOG_DIR}/abc.net.access.log combined
</VirtualHost>
and
<VirtualHost *:80>
ServerName xyz.net
ServerAlias www.xyz.net
ServerAdmin webmaster#localhost
DocumentRoot /var/www/xyz.net
ErrorLog ${APACHE_LOG_DIR}/xyz.net.error.log
CustomLog ${APACHE_LOG_DIR}/xyz.net.access.log combined
</VirtualHost>
apart from these I have default apache2 00-default-site.conf (unchanged)and rutorrent.conf
<VirtualHost *:80>
ServerAlias *
DocumentRoot /var/www/
CustomLog /var/log/apache2/rutorrent.log vhost_combined
ErrorLog /var/log/apache2/rutorrent_error.log
SCGIMount /rutorrent/RPC2 127.0.0.1:5000
<Directory "/var/www/rutorrent">
AuthName "user1"
AuthType Basic
Require valid-user
AuthUserFile /var/www/rutorrent/.htpasswd
</Directory>
</VirtualHost>
Assuming my ip as t.u.v.w I have following /etc/hosts file set
127.0.0.1 localhost
127.0.1.1 template.pcsmarthosting.co.uk template
t.u.v.w abc.net
t.u.v.w xyz.net
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
I am able to access www.abc.net correctly as it goes to correct folder, however www.xyz.net goes to /var/www/ same as http://t.u.v.w
www.xyz.net doesn't work even when it is the only enabled site.
How do I fix this?
Systems hostname might be www.xyz.net , which means that 000-default acts as if it has "ServerName www.xyz.net" implicitly.
You should put a dummy ServerName in the 000-default so there's no risk.
I am following RiggsFolly answer, on this question and these examples and so far everything went well, but when I click on the vhost FF says that it can't find the server. How can this fixed?
I am using Wampserver 2.5.
I get this in the adress bar : http://www.cakeprebuild.com/
httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /wamp/www/CakePreBuild
ServerName www.CakePreBuild.com
<Directory "c:/wamp/www/CakePreBuild">
AllowOverride All
Require local
</Directory>
</VirtualHost>
hosts
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 localhost
127.0.0.1 CakePreBuild
::1 localhost
::1 CakePreBuild
Try these changes
Your VHOSTS Definition
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/CakePreBuild"
ServerName cakeprebuild.com
ServerAlias www.cakeprebuild.com
<Directory "c:/wamp/www/CakePreBuild">
AllowOverride All
Require local
</Directory>
</VirtualHost>
Your HOSTS file
127.0.0.1 localhost
127.0.0.1 cakeprebuild.com
::1 localhost
::1 cakeprebuild.com
Personally I would avoid using the .com tld for sites your are developing and use something like .dev.
If a site actually existed called cakeprebuild.com having added that name to the HOSTS file would mean you would never be able to access the actual live site from this PC as you have redirected it to this PC.
I'm guessing wamp is not configured correctly for your vhost. FF (and chrome to a lesser degree) will try and help you out add the
'http://www.' and '.com'
around what you entered, if what you entered didn't return a result. Turn off wamp and type in 'localhost', you'll be redirected to
http://www.localhost.com
I have the following vhosts config:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/projects/mycheck.il"
ServerName mobile.mycheck
ErrorLog "logs/mobile.mycheck.log"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/projects/api.il"
ServerName api.mycheck
ErrorLog "logs/api.mycheck.log"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/projects/admin"
ServerName front.mycheck
ErrorLog "logs/front.mycheck.log"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
ErrorLog "logs/localhost.log"
</VirtualHost>
and using windows, I have the following hosts file
127.0.0.1 localhost
127.0.0.1 mobile.mycheck
127.0.0.1 api.mycheck
127.0.0.1 front.mycheck
However, no matter what vhost I try to put in my browser, I always resolve to the same directory (projects/mycheck.il), any idea how to fix this?
Try adding the following line before your VirtualHost declarations:
NameVirtualHost *:80
I have XAMPP installed for local development and I'd like to create a sub domain for each project. In my apache vhosts config I've put this:
<VirtualHost localhost:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
ServerAdmin admin#localhost
</VirtualHost>
<VirtualHost nexus.localhost:80>
DocumentRoot C:/xampp/htdocs/nexus/
ServerName nexus.localhost
ServerAdmin admin#nexus.localhost
</VirtualHost>
And in my Windows hosts file:
# development
127.0.0.1 localhost
127.0.0.1 nexus.localhost
localhost works as normal. As in, if I go to http://localhost/project_name everything works fine. However, if I navigate to http://nexus.localhost/ I just get Object not found! errors.
What could be wrong here? Thank you.
The documentation http://httpd.apache.org/docs/2.2/mod/core.html#virtualhost says that the <VirtualHost> directive should contain the IP address, so try this instead:
<VirtualHost 127.0.0.1:80>
DocumentRoot C:/xampp/htdocs/
ServerName localhost
ServerAdmin admin#localhost
</VirtualHost>
<VirtualHost 127.0.0.1:80>
DocumentRoot C:/xampp/htdocs/nexus/
ServerName nexus.localhost
ServerAdmin admin#nexus.localhost
</VirtualHost>