dns points to wrong directory - apache

I'm trying to setup two virtual hosts in windows using xampp. From what I've read one have to alter the windows hosts file and xampp's httpd-vhosts.conf file.
hosts file:
127.0.0.1 gholizadeh
127.0.0.1 doostr
127.0.0.1 localhost
vhosts file:
NameVirtualHost *:80
<VirtualHost gholizadeh>
DocumentRoot "E:\xampp\htdocs\lowkey\pappa"
ServerName gholizadeh.se
ServerAlias www.gholizadeh.se
<Directory "E:\xampp\htdocs\lowkey\pappa">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost doostr>
DocumentRoot "E:\xampp\htdocs\lowkey"
ServerName doostr.com
ServerAlias www.doostr.com
<Directory "E:\xampp\htdocs\lowkey">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost localhost>
DocumentRoot "E:\xampp"
ServerName localhost
<Directory "E:\xampp">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
But I'm having problem accessing these files. When I try it from my own LAN I get prompted to the xampp site and when get access denied when trying to enter it from extern network. What am I doing wrong?

You got the VirtualHost command wrong. Use it like this instead:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName gholizadeh.se
ServerAlias www.gholizadeh.se
DocumentRoot "E:\xampp\htdocs\lowkey\pappa"
<Directory "E:\xampp\htdocs\lowkey\pappa">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName doostr.com
ServerAlias www.doostr.com
DocumentRoot "E:\xampp\htdocs\lowkey"
<Directory "E:\xampp\htdocs\lowkey">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "E:\xampp"
<Directory "E:\xampp">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Some more things:
* you should add a ServerAdminto each host
* the entries in the host file are just for internal debugging purposes, I assume?
And a side remark:
you don't plan to serve real web pages in the internet from this MS-Windows system, do you?

Related

apache virtualhost - localhost and development alias/servername

I'm trying to configure my apache vhosts file to have a localhost/something hostname and "alias" hostnames. I'm working with google api's currenctly and they are not accepting custom aliases as url's, so I can't make it work with my custom url's. Any thoughts of what to do? My current config that's not working:
<VirtualHost 127.0.0.1:80>
ServerName localhost/go
ServerAlias localhost/go
DocumentRoot "D:/username/Web/server.dev/go"
</VirtualHost>
<Directory "D:/username/Web/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
<VirtualHost *:80>
ServerName api.server.dev
ServerAlias api.server.dev
DocumentRoot "D:/username/Web/server.dev/api"
</VirtualHost>
##... more custom urls with subdomains cut out because it's unnecessary
<VirtualHost *:80>
ServerName adstrck.server.dev
DocumentRoot "D:/username/Web/server.dev/adstrck"
</VirtualHost>
### ALL OTHERS ###
<VirtualHost *:80>
ServerName www.server.dev
ServerAlias server.dev *.server.dev
DocumentRoot D:/username/Web/server.dev
</VirtualHost>
When I'm trying to access 127.0.0.1/go or localhost/go I get an internal server error.
Maybe what you want is something like this
<VirtualHost 127.0.0.1:80>
ServerName localhost
ServerAlias server.dev *.server.dev
DocumentRoot "D:/username/Web/server.dev"
</VirtualHost>
<Directory "D:/username/Web/server.dev">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
Require all granted
</Directory>
Then use a url like http://localhost/go to view the site.
Depending on your OS/browser, you may be able to add a development subdomain to localhost. E.g.
<VirtualHost *:80>
ServerName dev1.localhost
## rest of your config
## e.g. ServerAlias my.website.on.the.internet.com
DocumentRoot /var/www/dev1
</VirtualHost>
<VirtualHost *:80>
ServerName dev2.localhost
DocumentRoot /var/www/dev2
</VirtualHost>
# Default / catch-all
<VirtualHost *:80>
DocumentRoot /var/www/html
</VirtualHost>
I then pointed my browser to dev1.localhost and that resolved to dev1 and likewise for dev2.localhost and localhost by itself resolved to the default apache page.
This resolved my similar problem. Tested on Apache in a Debian WSL. Worked on Windows Chrome, failed on Windows Firefox. Based on this SO: https://stackoverflow.com/a/35124491

You don't have permission to access / on this server when I activate Virtual host in WAMP server

I'm trying to setup a virtual host on my server. I'm in windows server 2012. When I activate the vhost by uncomment the line Include conf/extra/httpd-vhosts.conf , I get this error:
You don't have permission to access / on this server
This is my httpd-vhosts.conf file
<VirtualHost *:80>
ServerAdmin webmaster#homemail.net
DocumentRoot "e:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "e:/wamp/www">
AllowOverride All
<IfDefine APACHE24>
Require local
</IfDefine>
<IfDefine !APACHE24>
Order Deny,Allow
Deny from all
Allow from 127.0.0.0 localhost ::1
</IfDefine>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "e:/wamp/www/test"
ServerName test.com
ErrorLog "logs/test-error.log"
CustomLog "logs/test-access.log" common
</VirtualHost>
Edit
After an day of trying to fix this problem, is this my current httpd-vhosts.conf file:
NameVirtualHost localhost
<VirtualHost localhost>
DocumentRoot E:/wamp/www/
ServerName localhost
</VirtualHost>
NameVirtualHost itp-recouvrement.bnpparibas
<VirtualHost test>
DocumentRoot E:/wamp/www/test/
ServerName exemple.fr
ServerAlias www.exemple.fr
ErrorLog "logs/test.log"
CustomLog "logs/test.log" common
<Directory />
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
</Directory>
</VirtualHost>
This is working locally, but not when I access the server from an another PC, I have same error before

vHosting on Apache2.2 won't work properly

So, I set up two virtual hosts on my apache and now, I can't access the server via localhost anymore.
Here's my vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#serv.net.local
DocumentRoot "W:/www"
<Directory "W:/www/">
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
ServerName serv.net.local
ErrorLog "logs/serv.net.local-error.log"
CustomLog "logs/serv.net.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#symfony.net.local
DocumentRoot "W:/www/symfony/web"
<Directory "W:/www/symfony/web/">
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
ServerName symdev.net.local
ServerAlias symfony.net.local
ErrorLog "logs/symdev.net.local-error.log"
CustomLog "logs/symdev.net.local-access.log" common
</VirtualHost>
All domains are in my hosts-file and are properly resolved. But I can only access the second vHost and get a connection reset error when trying to access localhost or serv.net.local. Same for using 127.0.0.1...
Any ideas whats wrong with this config?
According to discussion in comments, VirtualHost DocumentRoot was not readable because it contained no index, and directory listing was disabled, so fixing it solved the issue.

XAMPP Windows Apache VirtualHost 403 Forbidden

I had XAMPP running fine with virtual hosts on my winodws 8 machine until I was forced to restart my computer (windows update). After restarting I've noticed my virtual hosts weren't working any more. Instead of trouble shooting too much I decided to reinstall XAMPP (currently have XAMPP 3.1.0 running. Which is runnign Apache v 2.4.3)
I have my windows host file edited to redirect sitename.localhost to 127.0.0.1 and this is what I have in my httpd-vhost.conf:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\Users\USER\Documents\sitename"
ServerName sitename.localhost
<Directory "C:\Users\USER\Documents\sitename">
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Every time I try to access http://sitename.localhost I get a 403 Access Forbidden error. Any idea what I'm doing wrong?
Try adding Require all granted to the Directory configuration:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\Users\USER\Documents\sitename"
ServerName sitename.localhost
<Directory "C:\Users\USER\Documents\sitename">
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
Also, try to set reading permissions to the web site folder for Authenticated users.
This will list out as index.
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\USER\Documents\sitename"
ServerName projectname.dev
ServerAlias projectname.dev
<Directory "C:\Users\USER\Documents\sitename">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
could you test this code pls instead of yours?
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\Users\USER\Documents\sitename"
ServerName sitename.localhost
<Directory "C:\Users\USER\Documents\sitename">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
btw, do you have index.html/php file in folder "C:\Users\USER\Documents\sitename", don't you?

Configuring Apache vhost: sites having inner sites. possible?

i am wondering if i am doing some thing wrong
i have http://localhost pointing to the directory D:\Projects\Websites
then i want to create a inner site http://learningzf in D:\Projects\Websites\php\ZendFramework\LearningZF\public. this is so that i can use URL's like /users/login instead of specifying the full url
i find that if i add the entry in vhosts to point http://learningzf to D:\Projects\Websites\php\ZendFramework\LearningZF\public, localhost will also point to D:\Projects\Websites\php\ZendFramework\LearningZF\public
<VirtualHost *:80>
DocumentRoot "D:/Projects/Websites/php/ZendFramework/LearningZF/public"
ServerName localhost
</VirtualHost>
<Directory "D:/Projects/Websites/php/ZendFramework/LearningZF/public">
AllowOverride All
Options All
Order allow,deny
Allow from 127.0.0.1
</Directory>
<VirtualHost *:80>
DocumentRoot "D:/Projects/Websites"
ServerName localhost
</VirtualHost>
<Directory "D:/Projects/Websites">
AllowOverride All
Options All
Order allow,deny
Allow from 127.0.0.1
</Directory>
i noticed if i move the entries for learningzf below localhost, both learningzf &localhost will point to D:/Projects/Websites
UPDATE
following #KikoV answer, i have modified it to make it work ...
NameVirtualHost 127.0.0.1:80
<VirtualHost localhost:80>
ServerName localhost
DocumentRoot "D:/Projects/Websites"
<Directory "D:/Projects/Websites">
AllowOverride All
Options All
Order allow,deny
Allow from 127.0.0.1
</Directory>
</VirtualHost>
<VirtualHost learningzf:80>
ServerName learningzf
DocumentRoot "D:/Projects/Websites/php/ZendFramework/LearningZF/public"
<Directory "D:/Projects/Websites/php/ZendFramework/LearningZF/public">
AllowOverride All
Options All
Order allow,deny
Allow from 127.0.0.1
</Directory>
</VirtualHost>
You should use NameVirtualHost directive.
If host "learningzf" is pointing to localhost, (127.0.0.1), you could use:
Note: In _default _ , last underscore should go togheter.
NameVirtualHost 127.0.0.1:80
<VirtualHost _default _:80>
ServerName localhost
<Directory "D:/Projects/Websites">
AllowOverride All
Options All
Order allow,deny
Allow from 127.0.0.1
</Directory>
</VirtualHost>
<VirtualHost learningzf:80>
ServerName learningzf
<Directory D:/Projects/Websites/php/ZendFramework/LearningZF/public">
AllowOverride All
Options All
Order allow,deny
Allow from 127.0.0.1
</Directory>
</VirtualHost>
This way you could access to http://localhost and http://learningzf and Apache will know which should use.
(By default, it will go to D:/Projects/Websites).
Note2: remember to add "127.0.0.1 learningzf" line to c:/windows/system32/drivers/etc/hosts file in order to get hostname resolved.