0

I installed Apache httpd on CentOS 7 by yum. httpd is installed under /etc/httpd with tree

/etc/httpd
 |-- conf/
 |-- conf.d/
 |-- conf.module.d/
 |-- ...

Everything is default, now I want to try virtual host by adding a config file /etc/httpd/conf.d/test.conf :

<VirtualHost *:80>
    DocumentRoot /www/test
    ServerName www.example.com
    ServerAlias example.com
</VirtualHost>

and an html file /www/text/index.html

<!DOCTYPE html>
<html>
<body>
<p> test </p>
</body>
</html>

But www.example.com in my browser still direct to the default page.

Then I tried a different directory other than /www/test after reading some articles (I also added an html file /var/www/test/index.html):

<VirtualHost *:80>
    DocumentRoot /var/www/test
    ServerName www.example.com
    ServerAlias example.com
</VirtualHost>

This time it works! www.example.com in my browser does show the right page.

So obviously the problem is the directory /www, but why does httpd fail on /www while succeeding on /var/www? What's the difference? By the way, I have granted permission on /www to user apache

shintaroid
  • 1,556
  • 3
  • 20
  • 34
  • Do you have have "/www" directory? – Nitin Dhomse Oct 11 '17 at 09:06
  • Go in your host directory where you have your application ("test"), do pwd, get absolute path, try to replace that in DocumentRoot, also check apache service status and logs – Nitin Dhomse Oct 11 '17 at 09:18
  • Yes, I have directory /www. I tried changing DocumentRoot to /www/test (and delete virtual host config file), it directs to the default page. Something must be wrong, I guess? – shintaroid Oct 11 '17 at 09:41
  • Possible duplicate https://stackoverflow.com/questions/5570085/accessing-files-outside-the-document-root-with-apache – Paula Livingstone Oct 11 '17 at 09:46
  • You should use apache port forwarding feature to redirect your request to desired url in virtualhost (No need to remove virtualhost). – Nitin Dhomse Oct 11 '17 at 09:49

0 Answers0