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
Related
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 am having a problem with virtualhosting on my fedora 18 box.
http://127.0.0.1 works correctly and brings up index.html
http://127.0.0.1:9000 also works correctly.
http://localhost works
http://localhost:9000 does NOT work.
It just redirects to http://localhost
Why is not able to treat localhost and 127.0.0.1 the same way?
Here is the contents of my httpd-vhosts.conf:
Thanks in advance.
Listen 9000
DirectoryIndex index.html welcome.html
NameVirtualHost *:80
NameVirtualHost *:9000
<VirtualHost *:80>
ServerName saraslights
ServerAdmin ratteri#gmail.com
ServerAlias saraslights
DocumentRoot "/var/www/html/opencart"
ErrorLog "logs/saraslights-errors.log"
CustomLog "logs/saraslights-access.log" common
</VirtualHost>
<VirtualHost *:9000>
ServerName wordpress
ServerAdmin ratteri#gmail.com
ServerAlias wordpress
DocumentRoot /var/www/html/wordpress
ErrorLog "logs/wordpress-errors.log"
CustomLog "logs/wordpress-access.log" common
</VirtualHost>
I'm trying to enable multiple domains in my environment Development, but am not succeeding the way I tried below, at which point I'm wrong?
I installed httpd and changed DocumentRoot in httpd.conf to:
C:/Webserver/www
*I changed the Windows hosts file to(in Italics would like to access):
If I switch to 127.0.0.1 api.rotadorock the address resolves to www/ but the right is www/rotadorock/api.
127.0.0.1 localhost
127.0.0.1 webserver
127.0.0.1/rotadorock/ecommerce rotadorock
127.0.0.1/rotadorock/api api.rotadorock
127.0.0.1/rotadorock/ecommerce ecommerce.rotadorock
127.0.0.1/rotadorock/mobile mobile.rotadorock
127.0.0.1/rotadorock/sistema sistema.rotadorock
127.0.0.1/rotadorock/social social.rotadorock
*Update(windows hosts file)
I removed the hosts file changes I mentioned above, because as #Volker Birk said are not necessary. But even so, still can not access as desire (api.rotadorock/ or localhost/api.rotadorock/ and should point to C:/Webserver/www/rotadorock/api). What could be wrong?
And finally changed httpd-vhost.conf for:
NameVirtualHost webserver:80
<Directory "C:/Webserver/www">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "c:/Webserver/www"
ServerAlias localhost
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerName webserver
DocumentRoot "c:/Webserver/www"
ServerAlias webserver
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost rotadorock:80>
ServerName rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/ecommerce"
ServerAlias rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost api.rotadorock:80>
ServerName api.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/api"
ServerAlias api.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost ecommerce.rotadorock:80>
ServerName ecommerce.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/ecommerce"
ServerAlias ecommerce.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost mobile.rotadorock:80>
ServerName mobile.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/mobile"
ServerAlias mobile.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost sistema.rotadorock:80>
ServerName sistema.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/sistema"
ServerAlias sistema.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
<VirtualHost social.rotadorock:80>
ServerName social.rotadorock
DocumentRoot "c:/Webserver/www/rotadorock/social"
ServerAlias social.rotadorock
ErrorLog "logs/httpd-error.log"
CustomLog "logs/httpd-access.log" common
</VirtualHost>
You don't need the hosts file. Have a look into the documentation:
http://httpd.apache.org/docs/2.2/en/vhosts/name-based.html
Finally solved the problem. And I could just using the Windows hosts file and httpd-vhosts.conf httpd together.
Let me give an example of what was done to enable multiple subdomains accessing locally.
On Windows hosts file to add, for each domain and subdomain you want something like this:
127.0.0.1 api.rotadorock #my subdomain
127.0.0.1 rotadorock #my domain
And then the httpd-vhosts apache httpd:
# Accessing the API
<VirtualHost 127.0.0.1>
DocumentRoot "C:/Webserver/www/rotadorock/api"
ServerName api.rotadorock
ServerAlias ​​api.rotadorock
<Directory "C:/Webserver/www/rotadorock/api">
All Options Includes Indexes
</ Directory>
</VirtualHost>
# Accessing the domain
<VirtualHost 127.0.0.1>
DocumentRoot "C:/Webserver/www/rotadorock/"
ServerName rotadorock
ServerAlias ​​*.rotadorock
<Directory "C:/Webserver/www/rotadorock/">
All Options Includes Indexes
</Directory>
</VirtualHost>
And then that way I could access api.rotadorock/ and rotadorock/ locally. I tried all ways without the hosts file. But just gotta use it. If someone can explain to me how it should have done so it would not need to use the hosts I would be grateful.
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>
I've got a site set up on localhost that I'm actively developing, and I'd like to set up a subdomain on localhost to make my life 10* easier.
I added this to C:\xampp\apache\conf\extra\httpd-vhosts.conf:
<VirtualHost i1.localhost:80>
ServerAdmin dummy#localhost
DocumentRoot "C:/xampp/htdocs/i1/"
ServerName i1.localhost
ServerAlias www.i1.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>
Apache stats up fine, but when I navigate to http://localhost/ I'm seeing content from the i1 subdomain. http://i1.localhost/ works fine, however.
Then I tried doing this:
<VirtualHost localhost:80>
ServerAdmin dummy#localhost
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
ServerAlias www.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>
<VirtualHost i1.localhost:80>
ServerAdmin dummy#localhost
DocumentRoot "C:/xampp/htdocs/i1/"
ServerName i1.localhost
ServerAlias www.i1.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>
But that worked the opposite. On both localhost and i1.localhost I'm seeing content from C:/xampp/htdocs/.
Anyone got an idea what's going wrong?
Cheers.
Apache usually does not like a vhosts document root inside another vhost, try:
DocumentRoot "C:/xampp/htdocs/"
and
DocumentRoot "C:/xampp/i1/"