Configuring Virtual Hosts in Apache

Asked

Viewed 1,137 times

2

I’m trying to create a virtualhost here in the company, but it doesn’t work. The funny thing is that I created in the same way as other virtualhosts that are working normally.

Below is an example:

Virtualhost 1

<VirtualHost *>
    ServerName manobra.henriquestefani.com.br
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/bpm/intranet"
</VirtualHost>

Virtualhost 2

<VirtualHost *>
    ServerName retornoviagem.henriquestefani.com.br
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/retornoviagem"
</VirtualHost>

virtualhost1 works normally, while virtualhost2 does not.

  • Make sure you are not missing to put the new host in the file /etc/hosts.

  • Rodrigo in my etc/hosts file has only this line. 127.0.0.1 localhost &#Xa.

  • This host has to be in the file /etc/hosts of the machine where the sites are, and not your.

  • Have you enabled both in apache? Since it’s two different folders and one works and the other doesn’t, check the permission. An error appears in the log?

  • Yes he is in the machine where the sites are.

  • How do I check the permission?

  • @user5313 depends. Is your apache on Windows or Linux? Generally the apache user already has read and write permission in the htdocs directory and its contents. I think it would be more interesting if you put the server.log into a life frame...

  • My apache is on Windows.

  • http://www.pastebin.ca/2640564

  • @Oliver, you can even check the permissions of the directory you defined as virtual and make sure the apache user has read and write privileges, but I don’t think that’s the problem. But watch it anyway and put it there in the comments.

  • See if this link helps: http://www.vivaolinux.com.br/artigo/Virtual-Host-com-Apache/

  • What version of apache?

  • The apache version is 2.2. .

  • It is not necessary to put in the /etc/hosts. I have an apache with Virtualhosts here and I never had to put anything in it. In this case I think the domain itself is misconfigured in DNS.

Show 9 more comments

2 answers

2


In the apache 2.2 documentation, available at https://httpd.apache.org/docs/2.2/vhosts/name-based.html, the following example is given.

NameVirtualHost *:80

 <VirtualHost *:80>
ServerName www.domain.tld
 DocumentRoot /www/domain
 </VirtualHost>

 <VirtualHost *:80>
ServerName www.otherdomain.tld
 DocumentRoot /www/otherdomain
 </VirtualHost>

Apparently, by the documentation, the Namevirtualhost directive is mandatory, but I did not see it in your example.

When Apache receives a request pointing to an unknown domain, it is directed to the first Virtualhosts configuration. So, since your Virtualhosts2 doesn’t even open the page, it may be that the domain isn’t pointing to the correct IP, too.

0

It is necessary restart Apache after changing the settings, so that they take effect.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.