I'm running Apache2 on Debian Jessie, when i try to enter my site without www. it returns a 404 page.
What i have in apache config:
<VirtualHost *:80>
DocumentRoot "/var/www/sites/example.com"
ServerName www.example.com
ServerAlias example.com
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
DocumentRoot "/var/www/sites/example.com"
ServerName www.example.com
ServerAlias example.com
SSLCertificateFile /etc/chain.pem
SSLCertificateKeyFile /etc/key.pem
</VirtualHost>`
Now , there are no other definitions in "sites-enabled" that mentions the site
1- Both example.com and www.example.com have the same ip ( Not a DNS problem )
2- There are no extra configurations in "sites-available"
3- https://example.com works fine but http://example.com returns a 404
There was a <VirtualHost *:80> that has no ServerName , and apache used default server hostname which was example.com
Related
I am not able to setup subdomain through virtual host in my ubuntu server. Followed following steps
in /etc/hosts
127.0.0.1 localhost
10.0.0.1 domain.com
10.0.0.1 sub.domain.com
in /etc/apache2/sites-available/ i created two files domain.com and sub.domain.com
in domain.com file,
<VirtualHost *:80>
ServerAdmin webmaster#domain.com
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/
ErrorLog /var/www/domain.com/logs/error.log
CustomLog /var/www/domain.com/logs/access.log combined (all these folders exists)
</VirtualHost>
in sub.domain.com file,
<VirtualHost *:80>
ServerAdmin webmaster#sub.domain.com
ServerName sub.domain.com
ServerAlias www.sub.domain.com
DocumentRoot /var/www/sub.domain.com/
ErrorLog /var/www/sub.domain.com/logs/error.log
CustomLog /var/www/sub.domain.com/logs/access.log combined (all these folders exists)
</VirtualHost>
After this is i enabled the site by a2ensite domain.com, a2ensite sub.domain.com and then restarted apache server.
Domain.com works fine. But sub.domain.com is not working. I am getting error "Webpage not available".
Can anyone tell me what is the mistake i am doing??
I'm trying to configure two sites running on the same apache server with virtualhosts. Somehow whatever i try to configure apache has always problems with my config. Here is the configuration file
Listen 80
Listen 8080
NameVirtualHost 172.16.10.2:80
NameVirtualHost 172.16.10.2:8080
<VirtualHost 172.16.10.2:80>
ServerName be.wincars.local
DocumentRoot /var/www/wincarsbe
CustomLog /var/www/logs/wincarsbe.log combined
ErrorLog /var/www/logs/wincarsbe.log
</VirtualHost>
<VirtualHost 172.16.10.2:8080>
ServerName com.wincars.local
DocumentRoot /var/www/wincarscom
CustomLog/var/www/logs/wincarscom.log combined
ErrorLog /var/www/logs/wincarscom.log
</VirtualHost>
When i try to restart apache, here is what I get:
Try something like
Listen 80
....
NameVirtualHost *:80
<VirtualHost *:80>
ServerName be.wincars.local
...
</VirtualHost>
<VirtualHost *:80>
ServerName com.wincars.local
...
</VirtualHost>
You can also try make Apache dump out information about configured VirtualHosts:
httpd -t -D DUMP_VHOSTS
How i can correctly direct multiple url in a same conf file.let me know if i am correct to put my conf file like this
<VirtualHost *:80>
ServerName domain1.com
ServerAlias domain2.com
... real vhost settings ...
</VirtualHost>
and what if user could'nt find the url then he should me directed to a default page.please if anyone can tell me how i can put a redirection to a defult only if that url is not found.
You can set up apache vhosts like this:
<VirtualHost *:80>
ServerName domain1.com
ServerAlias *.domain1.com
ServerAlias domain2.com
ErrorDocument 404 /errors/error404.php
#... real vhost settings ...
</VirtualHost>
Any not found URL will be redirected to /errors/error404.php, or any URL you give here.
Ref http://en.wikipedia.org/wiki/HTTP_404.
For ServerAlias domain2.com, you must set up first a bind primary zone for this domain in your name server, this cname will point to your server's IP, otherwise, this line will have no effect.
What I need is as follows
I am able to access the sub domain in my local machine as follows test.localhost but I need test.myMachineName or test.myMachineIp to access from another computer in my own network
I have setup the sub domain in my local wamp server as follows:
IN https-vhost.conf:
<VirtualHost *:80>
#ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
#ErrorLog "logs/dummy-host.example.com-error.log"
#CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
#ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/wamp/www/test"
ServerName localhost
ServerAlias test.localhost
#ErrorLog "logs/dummy-host.example.com-error.log"
#CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
And then enabled vhost in httpd.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Then added in windows host as follows
127.0.0.1 test.localhost
I don't understand your configuration. First, if you access test.localhost from another computer will not work because your website does not exist on that computer. You have to use the IP address and port forwarding in your router settings (Private IP: Computer local IP, Type: TCP, Range: 80 - 80).
In https-vhost.conf:
<VirtualHost *:80>
#ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
#ErrorLog "logs/dummy-host.example.com-error.log"
#CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
#ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "c:/wamp/www/test"
ServerName test.youripaddress
ServerAlias test.youripaddress
#ErrorLog "logs/dummy-host.example.com-error.log"
#CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
In HOST file:
127.0.0.1 localhost
youripaddress test.youripaddress
Ask me any questions.
Some details
XAMPP 1.7.1
OS tested on vista and xp
Hello everyone. I have some problems with configuring my virtual hosts.
Currently I have two sites.
Here is my vhost.conf file:
<VirtualHost *:80>
ServerAdmin me#site.nl
DocumentRoot c:/xampp/htdocs/site1/trunk/
ServerName site1.local
</VirtualHost>
<VirtualHost *:80>
ServerAdmin me#site.nl
DocumentRoot c:/xampp/htdocs/site2/trunk/
ServerName site2.local
</VirtualHost>
And of course in my host file I have
127.0.0.1 site1.local
127.0.0.1 site2.local
I have restarted apache as well as my browser various times.
Here is my problem:
http://site1.local works. But when i go to http://site2.local, I land at site1.local.
any idea's?
Try
<VirtualHost "site1.local">
ServerAdmin spam#a1230912##ad#.nl
DocumentRoot c:/xampp/htdocs/site1/trunk/
ServerName site1.local
</VirtualHost>
<VirtualHost "site2.local">
ServerAdmin spam#a1230912##ad#.nl
DocumentRoot c:/xampp/htdocs/site2/trunk/
ServerName site2.local
</VirtualHost>
You always get site1 because Apache default to the first.
edit
Uncomment
#NameVirtualHost *
to
NameVirtualHost *
In your httpd.conf
Mine says (/etc/httpd/conf/httpd.conf)
126 # Listen: Allows you to bind Apache to specific IP addresses and/or
127 # ports, in addition to the default. See also the <VirtualHost>
128 # directive.
129 #
130 # Change this to Listen on specific IP addresses as shown below to
131 # prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
132 #
133 Listen 127.0.0.1:80
134 NameVirtualHost 127.0.0.1
And my vhost file has
<VirtualHost "www.whatever.com">
DocumentRoot /var/www/html/whatever/pub
ErrorLog logs/error_log
ServerName www.whatever.com
...