2

For example, the document root of virtualHost is /var/www, and server name is aaa.com. However, apache will tell me forbidden if I access the server with localhost and aaa.com. If I change the Directory option in http.conf to /var/www, apache will work well. I don't know why?

I want to set Directory option in every httpd-vhosts.conf, not in httpd.conf, how I can do it?

Here is my http.conf:

enter image description here

Here is my httpd-vhosts.conf:

enter image description here

ADreNaLiNe-DJ
  • 4,787
  • 3
  • 26
  • 35
remy
  • 1,255
  • 6
  • 20
  • 27
  • You have a mistype in `http.conf` - (4 w`s) – s.webbandit May 04 '12 at 11:38
  • you should have a default host and the extra virtual host settings with their own `DocumentRoot` and other own settings. If these settings are after each other, what's the problem? You could be more specific, your question is a bit unclear to me. So, what if you put the "default" host settings to the file `httpd-vhosts.conf`, AND after that, you put the other `VirtualHost` settings too. EDIT: oh yeah, I just saw webbandit's comment, he's absolutely right. – Sk8erPeter May 04 '12 at 12:00

3 Answers3

12

In http.conf file you should define options for only <Directory />. All the options of VirtualHosts you should define in httpd-vhosts.conf files. Something like:

httpd.conf:

DocumentRoot "/var/www"

<Directory />
        Order deny,allow
        Deny from all
        Options None
        AllowOverride None
</Directory>

httpd-vhosts.conf:

ServerName aaa.com
DocumentRoot /var/www

<Directory /var/www>
        Options FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
</Directory>
s.webbandit
  • 16,332
  • 16
  • 58
  • 82
6

This configuration was valid for apache version 2.2

First check your apache version by typing apachectl -V in your terminal.

If it shows something like this

Server version: Apache/2.4.27 (Ubuntu)
Server built:   2018-04-18T14:20:05

then your apache version has updated but the conf you are using is deprecated.

So instead of

2.2 configuration:

Order allow,deny
Allow from all

use this:

2.4 configuration:

Require all granted

For further documentation related to the upgrade, follow the official docs:

http://httpd.apache.org/docs/current/upgrading.html

hacksdump
  • 71
  • 2
  • 5
1

2.4 configuration:

<Directory />

Options All
AllowOverride All

</Directory>
Ryosuke Hujisawa
  • 2,682
  • 1
  • 17
  • 18