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>
Related
I have setup a sub-domain using httpd-vhosts.conf file on Xampp (Windows), the sub domain is accessible via Chrome and Opera on subdomain.localhost but Firefox and Edge can't resolve the address. However, localhost (the main domain) works on all browsers.
#localhost
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
ServerAlias www.localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
#subdomain
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:/xampp/htdocs/subdomain"
ServerName subdomain.localhost
ServerAlias www.subdomain.localhost
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
I had the same problem. Here's my solution:
After you create virtual hosts in httpd-vhosts.conf you must add your sub-domain to hosts file. It is located at c:\windows\system32\drivers\etc\hosts in windows.
You should add
127.0.0.1 subdomain.localhost
I set VirtualHost in httpd.conf like this:
<VirtualHost xxx.255.118.79:80>
ServerAdmin hoge#hoge.foo.com
DocumentRoot /var/www/html
ServerName main.foo.com
ErrorLog logs/main.foo.com-error_log
TransferLog logs/main.foo.com-access_log
</VirtualHost>
<VirtualHost xxx.255.118.79:8080>
ServerAdmin hoge#hoge.foo.com
DocumentRoot /opt/another_www/
ServerName anotherhost.foo.com
ErrorLog logs/host.foo.com-error_log
TransferLog logs/host.foo.com-access_log
</VirtualHost>
And it looks like ok with httpd -S.
[iron#birdwatch html]$ sudo httpd -S
VirtualHost configuration:
xxx.255.118.79:80 main.foo.com (/etc/httpd/conf/httpd.conf:1012)
xxx.255.118.79:8080 anotherhost.foo.com (/etc/httpd/conf/httpd.conf:1020)
Syntax OK
But when I access to http://xxx.255.118.79:8080, it still access to /var/www/html.
Could you kindly tell me how I can make apache2 serve /opt/another_www for port 8080 ?
Thanks!
I realized that the domain name in has to be discoverable by the local machine that runs Apache.
It means it has to be local IP address or *.
<VirtualHost *:8080>
ServerAdmin hoge#hoge.foo.com
DocumentRoot /opt/another_www/
After I changed it to *, it started to serve documents under /opt/another/www.
I have cofigured httpd-vhosts.conf as
<VirtualHost *:80>
ServerAdmin webmaster#repos
DocumentRoot "C:\Users\Naveed-Laptop\repos\ustainable"
ServerName ustainable
ErrorLog "logs/ustainable-error.log"
CustomLog "logs/ustainable-acess.log" common
</VirtualHost>
Configured my hosts file
127.0.0.1 ustainable
but when i go to google chrome search and search for
[http://ustainable]
it says
Oops! Google Chrome could not connect to ustainable
Suggestions:
Search on Google:
it was creating issue due to hotspot sheild and ErrorLog, CustomLog; i am using xampp 1.8
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:\xampp\htdocs"
ServerName xampp.local
ServerAlias www.xampp.local
</VirtualHost>
<VirtualHost 127.0.0.1:80>
DocumentRoot "C:\xampp\htdocs\domain\html"
ServerName domain.local.com
ServerAlias www.domain.local.com
after adding it at the end of your httpd-vhosts.conf file restart your xampp and also add following lines to your hosts file available at C:\Windows\System32\Drivers\etc\hosts
127.0.0.1 domain.local.com
127.0.0.1 xampp.local
it will work for xampp 1.8 for remaining xampp versions hope so
I'm using virtual host. but I want that when user browses IP address, my server will serve resource in local host. The content of my virtual host config:
NameVirtualHost *:80
# for main web
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents
ServerName localhost
</VirtualHost>
<VirtualHost 127.0.0.1:80>
DocumentRoot /Library/WebServer/Documents
</VirtualHost>
<VirtualHost 192.168.1.6:80>
DocumentRoot /Library/WebServer/Documents
</VirtualHost>
#for other webs
...
When user type 192.168.1.6 in the browser, the resource in /Library/WebServer/Documents will be return. But I don't want to designate 192.168.1.6 explicitly, I want something like ..*.*
I changed
...
<VirtualHost 192.168.1.6:80>
DocumentRoot /Library/WebServer/Documents
</VirtualHost>
...
to
...
<VirtualHost *.*.*.*:80>
DocumentRoot /Library/WebServer/Documents
</VirtualHost>
...
but it don't work.
What should I change? Is this even possible?
I am personally using this one for IP Vhost
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin contact#steelbrain.com.pk
DocumentRoot /var/www/ipbased/
ServerName 192.168.1.1
ServerAlias 192.168.1.1 192.168.1.2
</VirtualHost>
I have got one IP address on my sv, and I want to set up two domains on one Apache Server with another DocumentRoot. Here is wat I got in httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:\wamp\www\mail"
ServerName mail.A.pl
</VirtualHost>
<VirtualHost *:80>
ServerName B.eu
DocumentRoot "c:\wamp\www\B"
</VirtualHost>
<VirtualHost *:80>
ServerName A.pl
DocumentRoot "c:\wamp\www"
</VirtualHost>
Even when I try to load page: http://www.A.pl or www.B.eu or B.eu or A.pl it loads mail.A.pl.
What am I doing wrong?
EDITED
Here is new httpd-vhost, now it loads correct pages, but f.e. for A.pl doesn't show any images, and on mail.A.pl doesn't want to send POST data:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\wamp\www\mail"
ServerAlias mail.A.pl
ServerName mail.A.pl
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName B.eu
ServerAlias *.B.eu
DocumentRoot "c:\wamp\www\B"
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName A.pl
ServerAlias A.pl
DocumentRoot "c:\wamp\www"
</VirtualHost>
EDIT2
Thank you both for help.
I just switched first VirtualHost with last and it mistery started working :O
There are a few things that you need to have I think.
1) Uncomment the Virtual hosts line in Apache's config file so it includes httpd-vhosts.conf. On OSX that is:
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
2) Put the necessary lines in your hosts file ( http://en.wikipedia.org/wiki/Hosts_(file) ):
127.0.0.1 mail.A.pl
127.0.0.1 A.pl
127.0.0.1 B.pl
127.0.0.1 every.A.pl
127.0.0.1 subdomain.A.pl
127.0.0.1 needs-a-line.A.pl
The ServerAlias can go actually, you don't need that for subdomains, only for similar "main" domains.
Your httpd-vhosts.conf file is fine.
Why the images and POSTs are not working I don't know. That doesn't have anything to do with this host file. Perhaps with another .htaccess file.
You need to map NameVirtualHost to the IP address 127.0.0.1 for mapping multiple virtual host.
For example:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot 'C:\wamp\www'
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName myclient.local
DocumentRoot 'C:\wamp\www\ClientsMyClient'
</VirtualHost>
Have a look at this tutorial.