Setting a ServerName in the VirtualHost of Apache server is not working - apache

I have tried to create a new Virtual Host in my Apache server, but I cannot address it by its new ServerName "mysite.game".
Can you spot any mistake in my code, please?
OUTPUT
What happens is that the URL http://localhost:8081/ is displaying the right website directory, while "http://mysite.game" is giving the same error HTTP Error 404.
INPUT
This is what i have done.
In C:\Windows\System32\drivers\etc\hosts, i inserted the line:
127.0.0.1 mysite.game
In http.conf I added:
Listen 0.0.0.0:8081
Listen [::0]:8081
and
<Directory "C:\game">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
In httpd-vhosts.conf, I added:
NameVirtualHost *:8081
<VirtualHost *:8081>
DocumentRoot "C:\game"
ServerName mysite.game
<Directory "C:\game">
Order Deny,Allow
Allow from all
Require all granted
</Directory>
</VirtualHost>

Related

XAMPP virtualhost site with all configs not working

I am trying to run site my.com locally on XAMPP's apache server. Here my configurations in httpd-vhosts.conf file in the path ...\XAMPP\apache\conf\extra:
<VirtualHost *:80>
DocumentRoot "D:/IDEs/XAMPP/htdocs"
ServerName localhost
<Directory "D:/IDEs/XAMPP/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/IDEs/Websites/my.com"
ServerName my.com
<Directory "D:/IDEs/Websites/my.com">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Also, I remembered to add two lines in the hosts file, with is located in C:\Windows\System32\drivers\etc:
127.0.0.1 localhost
127.0.0.1 my.com
However, when I enter via link 'my.com' with enabled apache server, I've got only page with folder directories, which are in htdocs XAMPP's folder.
I have checked a lot of videos and stackoverflow questions, but nothing helped.
I would be pleased if you could help me with solving this issue.
first you should arrange directories on httpd.conf
example:
<Directory "C:/SERVER~1/web/site1">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "C:/SERVER~1/web/site2">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and then arrange vhosts.conf like this
example :
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.site1.com
DocumentRoot "C:/SERVER~1/web/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName site1.com
DocumentRoot "C:/SERVER~1/web/site1"
</VirtualHost>
<VirtualHost *:80>
ServerName www.site2.com
DocumentRoot "C:/SERVER~1/web/site2"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
DocumentRoot "C:/SERVER~1/web/site2"
</VirtualHost>
After five days-night of reading, searching, trying, I finnally fould the solution and done it in some steps:
First of all, forget about every file, and concentrate on the httpd-ssl.conf which is located in D:\IDEs\XAMPP\apache\conf\extra.
Second:
find the line "SSL Virtual Host Context" which has been commented. And below, find the line <VirtualHost _default_:443>.or simmilar. Then change it to <VirtualHost *:443>.
Third, change document root to the path of xampp's htdocs, for example, "D:/XAMPP/htdocs". Also, change ServerName from www.example.com:443 or similar, to localhost.
Here we done.
And Finally, after line </VirtualHost>, insert code
<VirtualHost *:443>
DocumentRoot "D:/IDEs/Websites/my.com"
ServerName my.com
<Directory "D:/IDEs/Websites/my.com">
Require all granted
</Directory>
</VirtualHost>
Change Document Root and Directory paths to your website location. And Servername to your server name.
RESTART APACHE
it works for me.
I also understood than some website uses SSL on localhost while the others not.
SO if you have exception like Apache/2.4.37 (Win32) OpenSSL/1.0.2p PHP/7.0.33 Server at my.com Port 443 you shold add your virtualhost configs into httpd-ssl.conf file.
If you got like ... Port 80 add yourl virtualhost configs into httpd-vhosts.conf

Virtual Hosts on WAMP causing 403 forbidden on 192.168.1.6… other aliases still work

recently modified httpd.conf and httpd-vhosts.conf to add vhosts...
#IncludeOptional "E:/wamp/vhosts/*"
Include "E:/wamp/alias/*"
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "e:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "e:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
Require ip 192.168.1
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot E:/activeWork/projects
ServerName projects.local
<Directory "E:/activeWork/projects">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot E:/activeWork/projects
ServerName www.projects.local
<Directory "E:/activeWork/projects">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot E:/activeWork/projects
ServerName api.projects.local
<Directory "E:/activeWork/projects">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
after that when i try to load 192.168.1.6 or 127.0.0.1 , gives me :
Forbidden
You don't have permission to access / on this server.
i've tried to solve it whit this answer but not works for me
and by recommandation in answers i check my access.log and this is the result:
192.168.1.6 - - [03/Oct/2016:11:03:00 +0330] "GET / HTTP/1.1" 403 288
127.0.0.1 - - [03/Oct/2016:11:00:55 +0330] "GET / HTTP/1.1" 403 286
if you are sure that your wamp Installation path is inside E:
then I suggest you to check your access log and error log to collect more information.
I assume you are using Apache 2.4 or later on your Wampserver? If so, then replace the require rules with "Require all granted" in your vhosts, like this:
<VirtualHost *:80>
DocumentRoot "e:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "e:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
If it still doesn't work, check if your firewall is blocking your access.
my problem is to define 3 vhost point to same directory and this confused apache...finally tnx to riggsfolly i fixed that...beside of this i make changes from this guide to define VHost to have setup things in a right way

Virtual host - Not Found

I wolud like to use virtual host on Apache 2.4
I use Xampp and I will have more site so on it.
I have already read some guide and I have edit my httpd.config
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
and the Load
also my defalut port in busy, so I have set
Listen 8080
After that I edit my httpd-vhosts.conf in this way
NameVirtualHost *:8080
<VirtualHost *:8080>
DocumentRoot "C:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:8080>
ServerName sample.locl
DocumentRoot "C:\wwww\sample"
<Directory "C:\wwww\sample">
DirectoryIndex index.php
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8080>
ServerName sample2.locl
DocumentRoot "C:\wwww\sample2"
<Directory "C:\wwww\sample2">
DirectoryIndex index.php
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
N.B. my site is in C:/www/sample and c:/www/sample2 and my xampp in in c:/xampp.
At the end I edit my host in system32 with
127.0.0.1 localhost
127.0.0.1 sample
127.0.0.1 sample2
Now I have 404 error, neither when I wrote: "localhost" in my url browser.
If i Understand how it work I suppose that when i write localhost it will be redirect to C:\xampp\htdocs and so I should see my xampp page but it's not so.. where did I go wrong?
I always recive
Not Found
HTTP Error 404. The requested resource is not found.
thanks in advance

Apache vhost always show me the same content on different subdomains

I have two subdomains on my VPS, i have registered the two subdomains in my DNS pointing to the same IP address.
the version installed is Server version: Apache/2.4.7 for Ubuntu 12.04.
I've enabled the sites with the a2ensite command and i have enable the module vhost_alias. restart and reloaded many times
stable.mydomain.com
<VirtualHost *:80>
ServerName stable.mydomain.com
DocumentRoot /var/www/stable/web
<Directory /var/www/stable/web>
Options Indexes FollowSymLinks Includes
AllowOverride All
order allow,deny
Allow from all
</Directory>
</VirtualHost>
beta.mydomain.com
<VirtualHost *:80>
ServerName beta.mydomain.com
DocumentRoot /var/www/beta/web
<Directory /var/www/beta/web>
Options Indexes FollowSymLinks Includes
AllowOverride All
order allow,deny
Allow from all
</Directory>
</VirtualHost>
my trouble is pointing my browser to any url always i get the same content and to add more confusion when i execute service apache2 reload in the two subdomains i get the content from beta.mydomain.com and when execute service apache2 restart in the two subdomains i get the content of stable.mydomain.com.
I have spent about 5 hours trying to fix this
update
event i try with the VirtualDocumentRoot
<Virtualhost *:80>
VirtualDocumentRoot "/var/www/%1/web"
ServerName stable.mydomain.com
ServerAlias *.mydomain.com
UseCanonicalName Off
<Directory "/var/www/*">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</Virtualhost>
with the same behavior explained before this update
Have you uncommented this line before defining the virtual hosts?
NameVirtualHost *:80

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.