0

I have this virtual host entry in my apache configuration. Server has only one IP address. If I put the server IP address in the browser, from which location the contents will serve? "/opt/bitnami/apache2/htdocs" or "/opt/bitnami/apps/wordpress/htdocs". Well, in my testing it shows that contents are served from "/opt/bitnami/apps/wordpress/htdocs". I want to know why.

<VirtualHost _default_:80>
 DocumentRoot "/opt/bitnami/apache2/htdocs"
  DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"

<Directory "/opt/bitnami/apache2/htdocs">
      Require all granted
</Directory>
<Directory "/opt/bitnami/apps/wordpress/htdocs">
      Require all granted
</Directory>

</VirtualHost>
2
  • I wonder if it's taking a round-robin approach to it. There seems to be no way it can distinguish between the two DocRoots apart from just choosing one at random and keeping it for the session. I wonder what'd happen if you try it from two different IP addresses (two different web clients). – kelvintechie Jul 14 '19 at 7:32
  • 1
    I don't think so. Because, this is the approach made by Bitnami in their wordpress stack. Wordpress contents are in /opt/bitnami/apps/wordpress/htdocs and a only a welcome page is there in /opt/bitnami/apache2/htdocs – Nevin Jul 14 '19 at 8:03
1

Well well well, it seems apache takes the last DocumentRoot. I switched the document root location like below and apache started serving the contents from "/opt/bitnami/apache2/htdocs"

<VirtualHost _default_:80>
  DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
 DocumentRoot "/opt/bitnami/apache2/htdocs"

<Directory "/opt/bitnami/apache2/htdocs">
      Require all granted
</Directory>
<Directory "/opt/bitnami/apps/wordpress/htdocs">
      Require all granted
</Directory>

</VirtualHost>
1
  • I kind of also suspected that...funny to see that it was simpler than round-robin! – kelvintechie Jul 14 '19 at 19:45
1

DocumentRoot is a directive that sets a value. Since there can be only one, in a given context, each subsequent call will overwrite the previous one. So the last one wins (for that specific context).

Using two directives in the same context seems useless, as only the second one matters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.