mod_autoindex on Apache 2.4 - apache

I am trying to setup a site with mod_autoindex and FancyIndexing that places my custom header above the directory listing. The problem that I am running into is that my system is acting as though my HEADER.html doesn't exist regardless of whether I tell it to use the one in the current directory or one in a fixed location like /repos/HEADER.html.
The config file autoindex.conf has
ReadmeName README.html
HeaderName HEADER.html
in it and I also tried adding these lines to the /repo directory section of my vhost but noting changed. This setup is on on CentOS 6.6 using Apache 2.4.6 and PHP 5.4.16 from CentOS's scl repo. Below is a copy of my vhost config for reference. Any help or suggestions would be greatly appreciated.
<VirtualHost 10.0.2.15:8080>
ServerName reflector.localdomain
## Vhost docroot
DocumentRoot "/opt/rh/httpd24/root/var/www/html"
## Alias declarations for resources outside the DocumentRoot
Alias /icons "/opt/rh/httpd24/root/usr/share/httpd/icons"
## Directories, there should at least be a declaration for /opt/rh/httpd24/root/var/www/html
<Directory "/opt/rh/httpd24/root/var/www/html">
Options FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
<Directory "/opt/rh/httpd24/root/var/www/html/repos">
Options Indexes FollowSymLinks MultiViews
IndexOptions FancyIndexing FoldersFirst IgnoreCase SuppressDescription VersionSort XHTML
AllowOverride None
Require all granted
DirectoryIndex disabled
</Directory>
## Logging
ErrorLog "/var/log/httpd24/MainSite_error.log"
ServerSignature Off
CustomLog "/var/log/httpd24/MainSite_access.log" combined
## Custom fragment
ProxyPassMatch "^/(.*\.php(/.*)?)$" "fcgi://127.0.0.1:9000/opt/rh/httpd24/root/var/www/html/$1"
</VirtualHost>

It turns out that mod_mime is needed for this. All I had to do was add include ::apache::mod::mime to my Puppet manifest and wala, it worked. I have verified this on the original setup of CentOS 6 + scl and on CentOS 7.

Related

How to properly set the allow and deny for apache 2.4 conf and vhosts

I need some advice on how to properly setup the vhosts file directives preferably without changing the apache2.conf contents. This is for apache 2.4.
Currently, I get AH01797: client denied by server configuration probably caused by the Require all denied in the apache2.conf.
apache2.conf:
<Directory />
Order Deny,Allow
Deny from all
Options None
AllowOverride None
Require all denied
</Directory>
vhosts file:
<IfModule mod_ssl.c>
<VirtualHost *:80>
ServerName sub.example.com
ServerAlias sub.example.com
<Directory /var/www/sub.example.com>
AllowOverride None
Allow from all
Require all granted
</Directory>
</VirtualHost>
</IfModule>
Thank you!
UPDATE
Adding this to the apache2.conf works, it just doesn't work in vhosts file. Any idea why?
<Directory /var/www/sub.example.com>
AllowOverride None
Allow from all
Require all granted
</Directory>
In 2.4, you shouldn't use Order, Deny, or Allow at all. Purge them and replace with Require.
UPDATE Adding this to the apache2.conf works, it just doesn't work in vhosts file. Any idea why?
Maybe the vhosts file isn't included in your configuration, or mod_ssl is not loaded so the whole thing is commented out? The IfModule doesn't make much sense here.

Apache Document Root adds leading default path

This should be a very simple question to answer for people who knows apache.
I have an Ubuntu computer which I use as my server. I have worked with apache several times before, but never experienced this issue.
My owncloud.conf file in the sites-enabled folder looks like this:
1 <VirtualHost *:80>¬
2 ServerName owncloud¬
3 DocumentRoot "~/mybook/ownCloud"¬
4 <Directory ~/mybook/ownCloud/>¬
5 Options None¬
6 Order deny,allow¬
7 Allow from all¬
8 </Directory>¬
9 </VirtualHost>
But after enabling the site and restarting apache, I'm getting this error:
AH00112: Warning: DocumentRoot [/etc/apache2/~/mybook/ownCloud] does not exist
I've been looking, and I cannot seem to find where it's set that "/etc/apache2/" should be leading default path to all set document roots of the site config files.
Does anyone know how I can remove this default setting?
Forget the comment I made regarding Mac, what you have above will not work. If you installed Apache on Ubuntu and accepted the defaults the docroot is /var/www and I am assuming you want your /mybook/ownCloud mapped to docroot. That is how you should do it because the httpd will run with group permissions to the real docroot. That can be done using an alias as I have below. Look at the bottom, but also note that I specified the correct default docroot in the beginning before I mapped anything. You can change the docroot but you will have to make sure the permissions on the new directory structure are set correctly.
I aliased your /mybook/ownCloud/ to ownCloud. Also, I have other directives that I removed from the sites-enabled code below for clarity.
BTW, I have personally never used tildes within an Apache conf file like you have above, it could be confusing during startup.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /owncloud/ "/mybook/ownCloud"
<Directory "/mybook/ownCloud">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
EDIT:
There are other ways to configure a VHost, but this is basically how it is done. You no longer set a server wide docroot declaration in httpd.conf. The /etc/apache2/ path is the server home and in the absence of a docroot declaration in your sites-enabled it may have defaulted to Server Home when httpd started.

Configure Apache2 to automatically append default file extention to a URL when one is not given

How do I configure Apache2 to load a page with the extensions of default files provided when a page is requested without an extension.
So for example I want http://webpage.com/page to automatically load either:
http://webpage.com/page.html OR
http://webpage.com/page.php
NOTE: I don't want any redirection or URL renaming to occur; meaning I want the address bar to still be showing http://webpage.com/page
Per CBroe's comments and his reference to apache docs httpd.apache.org/docs/2.2/content-negotiation.html#multiviews - Adding Multiviews to Options directive inside a Directory section solves this issue.
You can either add it to a Directory section like below (to affect all web applications under sites directory)
<Directory /sites>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
-OR- inside a site host definition
<VirtualHost *:80> #site.dev
ServerAdmin admin#email.com
ServerName site.dev
ServerAlias site.dev
DocumentRoot /sites/site.dev
<Directory /sites/site.dev>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>

Apache2 Option index on centos 6.3

On a newly installed Centos 6.3
I imported the config from Ubuntu for a virtualhost. Here is the piece of config
DocumentRoot /otherhome/test.cofares.net
ServerName test.cofares.net
<Directory "/otherhome/test.cofares.net">
allow from all
Options +Indexes
</Directory>
A request to the http://test.cofares.net I get the folowwing error in the error log
Directory index forbidden by Options directive: /otherhome/test.cofares.net/
The directory index worked for a sub directory http://test.cofares.net/test is OK
Any suggestions what is missing?
The same config work well with Ubuntu Server 12.04.
Try this. And make sure to restart apache after applying:
<Directory "/otherhome/test.cofares.net">
Options +Indexes FollowSymLinks
AllowOverride all
Order Allow, Deny
Allow from All
Satisfy All
</Directory>
And perhaps try this with Satisfy Any instead:
<Directory "/otherhome/test.cofares.net">
Options +Indexes FollowSymLinks
AllowOverride all
Order Allow, Deny
Allow from All
Satisfy Any
</Directory>
EDIT: Those didn’t seem to work? Then try this. Note I am setting up the whole <VirtualHost> directive & removed quotes from the <Directory> directive:
<VirtualHost *:80>
DocumentRoot /otherhome/test.cofares.net
ServerName test.cofares.net
<Directory /otherhome/test.cofares.net>
Options Indexes FollowSymLinks
Allow from All
</Directory>
</VirtualHost>
After digging a little I noticed that thire is a global rule (in conf.d/welcome.conf) that prevent indexing the / directory of any virtual server
By removing it it is now ok
Here is the rule that must be change
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>

Multiple versions of a website each with its own root directory using Apache

I have multiple versions of my website. Each resides in its own folder, for example:
site_v1/
index.html
page1.html
site_v2/
index.html
page1.html
How can I configure apache so that each version of the site has its own definition of the root directory?
In other words, I want site_v1/index.html to think the root directory is site_v1, and site_v2/index.html to think the root directory is site_v2
You are looking for the VirtualHost directive.
Apache manual on virtual hosts
As #Pekka wrote, you are indeed looking for the VirtualHost directive, but I though I might add an example configuration for your virtual host configuration. This should be placed in your httpd.conf file, edited to your preference, and remember to fill in the full path:
NameVirtualHost v1.yoursite.com:80
<VirtualHost v1.yoursite.com:80>
ServerName v1.yoursite.com
ServerAlias v1.yoursite.com
DocumentRoot /path/to/site_v1
ErrorLog /path/to/prefered/error.log
CustomLog /path/to/prefered/access.log combined
<Directory /path/to/site_v1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost v2.yoursite.com:80
<VirtualHost v2.yoursite.com:80>
ServerName v2.yoursite.com
ServerAlias v2.yoursite.com
DocumentRoot /path/to/site_v2
ErrorLog /path/to/prefered/error.log
CustomLog /path/to/prefered/access.log combined
<Directory /path/to/site_v2>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If you want, you may chose to use a different access/error log for each version of your site. Just change the name/path to the log file, and you're done. /path/to are the path to the site folder, and v1.yoursite.com & v2.yoursite.com should be changed to the relative domains you want to use for each version. If you don't want to change the log files, remove the ErrorLog and CustomLog directives and I'll default to the main log files set in httpd.conf