Xampp Virtual Hosts redirecting to localhost instead of the right folder - apache

I try to use a Virtual Hosts on xampp (apache 2.4), on Windows 10.
I've been through a lot of topics and posts and tried every combination of port etc, and I couldn't make it work.
When I try to access my project it redirects me to localhost (default).
Here's my system32/drivers/etc/hosts :
127.0.0.1 localhost
127.0.0.1 yanns-properties.test
Here's my httpd-vhosts.conf :
NameVirtualHost *:8080
<VirtualHost _default_:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
# Site: yanns-properties
<VirtualHost *:8080>
DocumentRoot "C:/xampp/htdocs/yanns-properties"
ServerName yanns-properties.test
CustomLog "C:/xampp/htdocs/yanns-properties/custom.log" combined
<Directory "C:/xampp/htdocs/yanns-properties">
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I also put in my httpd.conf file :
Listen 80
Listen 8080
When I try to access yanns-properties.test, it redirects me to localhost (with list of file since I renamed index).
I tested with various port, with my project in a different folder ... I don't know what to do anymore.
Thanks for your help !
I

Related

MAMP Apache Won't Start with Virtual Host for SimpleSAMLphp

I'm attempting to configure simpleSAMLphp within a MAMP/Apache environment on Windows 10 and below is my httpd-vhosts.conf file:
<VirtualHost *:80>
ServerName localhost
DocumentRoot C:/MAMP/htdocs
</VirtualHost>
<VirtualHost *:80>
ServerName simplesamlphp
DocumentRoot C:/MAMP/htdocs/pro-dashboard
Alias /simplesaml C:/MAMP/simplesamlphp/www
<Directory C:/MAMP/simplesamlphp/www>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And here is my /etc/hosts file:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
# Virtual Hosts
127.0.0.1 simplesamlphp
Apache starts via MAMP totally fine without including this httpd-vhosts.conf file in my httpd.conf file, but as soon as its included, Apache will not start so the issue appears to be with httpd-vhosts.conf. No errors are shown in the apache_error.log file. My Apache version is 2.2 so I believe my Directory directives in my second VirtualHost are correct.
I've tried double quoting the DocumentRoot's, directory paths etc, and also tried backslashes over forward slashes. I spent most of yesterday trying to figure this out while scouring the web but nothing I found has made this work.
Any help is much appreciated!
Try this modified config
The path in Directory header same as DocumentRoot!
<VirtualHost *:80>
ServerName localhost
DocumentRoot C:/MAMP/htdocs
</VirtualHost>
<VirtualHost *:80>
ServerName simplesamlphp
DocumentRoot C:/MAMP/htdocs/pro-dashboard
Alias /simplesaml C:/MAMP/simplesamlphp/www
<Directory C:/MAMP/htdocs/pro-dashboard>
Order allow,deny
Allow from all
AllowOverride All
</Directory>
</VirtualHost>
So oddly enough, taking out what I had in httpd-vhosts.conf and simply putting it in my httpd.conf file makes Apache start back up.

first VirtualHost must be localhost in httpd-vhosts.conf

Context: fresh wampserver 3.x install (windows10)
port 80 was used by microsoft iis so i change the port using wampserver tool (right click on the icon). Wampserver manage itself to change the port with 8080.
at this moment, httpd-vhosts.conf content is
# Virtual Hosts
#
<VirtualHost *:8080>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
and hosts content is:
#
127.0.0.1 localhost:8080
::1 localhost:8080
Purpose: create virtualhost for my project like http://myproject.localdev instead of http://localhost:8080/myproject/public/
what's going bad ?
by using wampserver link to create virtualhost, i got the error message below
first VirtualHost must be localhost in c:/wamp64/bin/apache/apache2.4.33/conf/extra/httpd-vhosts.conf
I used 8080 port too and had the same problem. What I've done - in httpd-vhosts.conf I added localhost with port 80 anyway, so I had both port 80 and port 8080:
<VirtualHost *:80>
ServerName localhost
....
<VirtualHost *:8080>
ServerName localhost
After that I opened localhost:8080 - there was a warning "Port used for the VirtualHost is not an Apache Listen port". Newertheless I clicked "Add a Virtual Host". The new host was added, then I restarted DNS (WAMP - Tools - Restart DNS).
After all you can delete from httpd-vhosts.conf localhost:80

Set up virtual hosts on Apache (XAMPP, Windows 10)

I try to set up virtual host for some local site with XAMPP.
I executed next steps:
In "C:/xampp/apache/conf/extra/httpd-vhosts.conf" I added:
<VirtualHost *:8081>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:8081>
DocumentRoot C:/xampp/htdocs/fw/public
ServerName fw.local.com
<Directory "C:/xampp/htdocs/fw/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Inside "C:/Windows/System32/drivers/etc/hosts" I added:
127.0.0.1 localhost
127.0.0.1 fw.local.com
Restarted Apache.
And...
If I follow to:
http://localhost:8081/
All is OK: I see my catalog with projects in folder "htdocs".
But! If I follow to:
http://fw.local.com/
I expect to see result of my "index.php" file inside "..htdocs/fw/public". But I get:
This site can’t be reached
fw.local.com refused to connect.
File "C:/xampp/apache/conf/httpd.conf" contains:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Where I was wrong?
You should change: <VirtualHost *:8081> to <VirtualHost *:80> on both counts, fw.local.com attempts to connect to port 80, not 8081.
Edit: You could also keep it the way you have it and connect to: http://fw.local.com:8081/

configuring virtual host and localhost redirecting to the xampp folder

I have problem with creating virtual host. I am using Windows 7 x64 Professional. In file C:\Windows\System32\drivers\etc\hosts I have only this lines:
127.0.0.1 myhost
127.0.0.1 www.myhost
And in file C:\xampp\apache\conf\extra\httpd-vhosts.conf I have this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/"
ServerName localhost
ServerAlias www.localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/Users/Me/Dropbox/Project/public"
ServerName myhost
ServerAlias www.myhost
<Directory "C:/Users/Me/Dropbox/Project/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And of course I have restared my Apache server after adding this lines in those files.
Unfortunatly typing myhost or www.myhost in my browser redirect me to the myhost/xampp.
I have already search and I have found on google and also on stackoverflow description how to configure virtual hosts using xampp but how can I recognize I have done everything alright. I know that my problem isn't new but I didn't found working solution for me.
I have also recognized that typing localhost in my browser redirect me alsto localhost/xampp. I don't know whether these problems are linked in my case.
I had this same issue. Your first request is redirecting to the htdocs root directory. If you look at index.php in the htdocs directory, you can see very brief code that takes the incoming request and redirects it to the xampp directory.
I fixed it by fiddling with the httpd-vhosts.conf file. In your case, try making the following edits:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "C:\xampp\htdocs\
ServerName localhost
</VirtualHost>
<VirtualHost www.myhost>
DocumentRoot "C:\Users\Me\Dropbox\Project\public"
ServerName www.myhost
ServerAlias www.myhost
<Directory "C:\Users\Me\Dropbox\Project\public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I had a similar issue and found that I had to go to my Apache24 main httpd.conf file and uncomment around line 501 "Include conf/extra/httpd-vhost.conf"
I had never used that before and it was still #'ed out. Hope this helped anyone not finding other answers here. My Apache24 can now see my vhost file.
You need to enable name-based virtual hosting.
Near the top of the file in C:\xampp\apache\conf\extra\httpd-vhosts
uncomment #NameVirtualHost *:80
i.e. from:
#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
To:
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
(Note the last line now is uncommented).
Worked like a charm for me. :)
try this
[ file : C:\xampp\apache\conf\extra\httpd-vhosts.conf ]
<VirtualHost basic.test:80>
DocumentRoot "C:/xampp/htdocs/basic/public/"
ServerName basic.test
</VirtualHost>
[ file : C:\Windows\System32\drivers\etc\hosts ]
(open as admin)
127.0.0.1 basic.test
127.0.0.1 localhost
For me replacing this one <VirtualHost *:80> to this <VirtualHost 127.0.0.1:80> working fine.

Multiple Virtual Hosts on Different Ports in WAMP

So I have this problem...
I use WAMP and have set up perfectly working Virtual Hosts in the past, but now I have come to something I never foresaw.
I am trying to do this:
Access C:\wamp\www through http://localhost
Access D:\somethingelse through http://localhost:8080 OR http://something.dev
I much prefer using the proper http://something.dev, as the working site is http://something.co, and so I can keep them separate.
I have followed guides and read forum posts, but all I have manages to do so far is this:
Access C:\wamp\www through http://localhost OR http://something.dev
Access D:\somethingelse through http://localhost:8080 OR http://something.dev:8080
Anybody got any idea how you would do this? Here's my VirtualHost Code:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "C:\wamp\www"
ServerName localhost
ServerAlias www.localhost.com
ErrorLog "logs/localhost-error.log"
CustomLog "logs/localhost-access.log" common
</VirtualHost>
<VirtualHost *:8080>
ServerAdmin webmaster#something
DocumentRoot "D:/something/www"
ServerName something.dev
ServerAlias www.something.dev
ErrorLog "logs/something-error.log"
CustomLog "logs/something-access.log" common
<directory "D:/something/www">
Options Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</directory>
</VirtualHost>
And in httpd.conf I have this
Listen *:80
Listen *:8080
And my hosts file is working and points both of these to 127.0.0.1
(The reason I want to do this is that when I code on my machine I use the http://something.dev, but I run Livereload Windows, and test my website simultaneously on an iPhone and iPad on the same local network, but without any access to iOS's equivalent of the hosts file. It also allows me to open up only a specific part of my server to the internet, through port forwarding on my router.)
I suppose you have solved the issue. Anyway is good to share some nice information on how to set up multiple Virtual Hosts in Wamp. This is working for me:
http://www.kristengrote.com/blog/articles/how-to-set-up-virtual-hosts-using-wamp
In my case I am working with ports 8080 and 8181. 8080 is redirecting to a subfolder under c:\wamp\www\myfolder, while 8181 is redirecting to root c:\wamp\www.
To make 8181 work I had to edit httpd-vhosts.conf, hosts (in \drivers\etc folder) and httpd.conf.
In httpd.conf my Apache is listening:
Listen 8080
Listen 8181
also I uncommented:
Include conf/extra/httpd-vhosts.conf
my root is pointing to
DocumentRoot "c:/wamp/www/myfolder"
root directory is configured as:
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from ::1
Allow from localhost
</Directory>
and added:
<VirtualHost *:8181>
DocumentRoot "C:\wamp\www"
ServerName name-of-my-fake-server
</VirtualHost>
in httpd-vhosts.conf I have set:
NameVirtualHost *:8181
in hosts (c:\windows\system32\drivers\etc) I have added:
127.0.0.1 localhost
127.0.0.1 name-of-my-fake-server #My Test Site
Doing that I have now two ports working 8080 and 8181: so 8080 points to directory "c:\wamp\www\myfolder" and the other port 8181 points to my root folder "c:\wamp\www\"
Using * as the hostname requires the use of NameVirtualHost:
NameVirtualHost *:80
NameVirtualHost *:8080
For those with MAMP, edit the httpd.conf
nano /Applications/MAMP/conf/apache/httpd.conf
Add Listen for each port
Listen 80
Listen 8080
And the ServerName too
ServerName localhost:80
ServerName localhost:8080
Once done that, edit httpd-vhosts.conf
nano /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Define NameVirtualHost
NameVirtualHost *:80
NameVirtualHost *:8080
And the VirtualHost's
<VirtualHost *:80>
DocumentRoot "/Users/yourUser/path/project1"
ServerName project1.local
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/Users/yourUser/path/project2"
ServerName project2.local
</VirtualHost>
Of course you need to have project1.local and project2.local in your hosts file
sudo nano /etc/hosts
And add
127.0.0.1 project1.local project2.local
Restart MAMP and you could access your vhost by
project1.local
project2.local:8080
project2 could be access also in your network or with a external IP (e.g to test from a different device like a mobile phone). Assuming your IP is 192.168.1.10
192.168.1.10:8080
The question is a little about it. But I assumed that it's near there and may be helpful for somebody.
Recently I met the problem when I need to get access to a few resources (debian repository, my website and phpmyadmin) by one external IP address and port.
After learning the problem I found technology named as reverse proxy. It like proxy but server is accepting all connection from many users and redirect to one target (your server).
I made simple Docker image and docker-compose file and push that to github.com/urpylka/docker-nginx-reverse-proxy and hub.docker.com.
Config file is very simple:
server {
listen 80;
server_name smirart.ru robotic.lol;
location / {
proxy_pass http://robotic.lol:1080/;
}
}
server {
listen 80;
server_name repo.smirart.ru;
location / {
proxy_pass http://8.8.8.8:2080/;
}
}
You can use that for few web-servers running by different IP.