i have problem in Apache 2.4 in Ubuntu 13.10. I try to change Document Root to /home/fandi/public_html And all working fine. But i try to create folder in my public_html/ i get an error like this :
[Sat Jan 25 10:59:50.149441 2014] [autoindex:error] [pid 1093] [client 127.0.0.1:39901] AH01276: Cannot serve directory /home/fandi/public_html/report_php/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
I must create file index.html
, index.php
and other index.xxx
file.
In default it must show Directory Index. How to enable Directory Index?
This is my file 000-default.conf
:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/fandi/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/home/fandi/public_html">
Options All
AllowOverride All
Require all granted
Options Indexes FollowSymLinks
</Directory>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Please help, thanks before ^^
Turns out you need to disable DirectoryIndex in Apache 2.4 to get auto Indexes.
DirectoryIndex disabled
Options Indexes
When DirectoryIndex is not disabled, auto index does not work and apache sends either a 403 Forbidden or a 404 File not found if you use fastcgi/php-fpm.
Here are the corresponding error log lines (for search purposes):
[authz_core:error] client denied by server configuration:
[proxy_fcgi:error] Got error 'Primary script unknown\n'
Options All <--turn on all options
Options Indexes FollowSymLinks <--- replace previously set options with these two
The second line is redundant, because you've already turned on all the options with the first line, and since the two options aren't prefixed with +
, they actually REPLACE the entire options list enabled set with All
with just those two individual options.
I managed to get it to work
Basically it seems that Apache2.4 doesn't carry over the settings from DocumentRoot to your virtual hosts unless the virtual hosts are subfolders of DocumentRoot, like previous versions used to do. Which kind of makes sense, but the change should be documented and it wasn't.
What I mean is, in your httpd.conf you'll have (this is an OS X one):
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
Options +Indexes +FollowSymLinks
# etc
</Directory>
And then in your extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/pth/to/somewhere/completely/different"
ServerName my-virtual-host.dev
ErrorLog "/private/var/log/apache2/my-virtual-host.dev-error_log"
CustomLog "/private/var/log/apache2/my-virtual-host.dev-access_log" common
</VirtualHost>
The VH used to inherit all the settings - not anymore if it's not a subfolder. So what you need to do is copy and paste the settings in the VH (or you can probably create another <directory
if you have a lot of VHs in the same place)
<VirtualHost *:80>
DocumentRoot "/pth/to/somewhere/completely/different"
ServerName my-virtual-host.dev
ErrorLog "/private/var/log/apache2/my-virtual-host.dev-error_log"
CustomLog "/private/var/log/apache2/my-virtual-host.dev-access_log" common
<Directory "/pth/to/somewhere/completely/different">
Options +Indexes
</Directory>
</VirtualHost>
It's the +Indexes which does the magic.
I had the same problem with Centos 7.2 and apache 2.4.
In new installation, the problem is most likely caused by welcome.conf
that disable Option Indexes in every location:
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
This file is restored on every Apache upgrade, then you should comment or delete previous lines.
In the log you can find an error
[Sun Dec 03 17:38:17.649269 2017] [autoindex:error] [pid 4806] [client ::1:57323] AH01276: Cannot serve directory /etc/httpd/conf/htdocs/: No matching DirectoryIndex () found, and server-generated directory index forbidden by Options directive
to fix it:-
then you must remove the line in /etc/httpd/conf.d/welcome.conf
below existing configuration:-
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
solved with the below configuration,:- commented out a line.
<LocationMatch "^/+$">
#Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
Add this line to you vhost.conf file for the site
DirectoryIndex default.html
And you are all set
for future people,if you follow all above and problem still occur,try this:
httpd.conf(make sure belows are open):
LoadModule alias_module modules/mod_alias.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule autoindex_module modules/mod_autoindex.so
Include conf/extra/httpd-autoindex.conf
extra/httpd-autoindex.conf:
<Directory "change to your directory">
来源:https://stackoverflow.com/questions/21346486/how-to-show-directory-index-in-apache-2-4-with-custom-document-root