How to troubleshoot index forbidden by Options directive error - apache

I am seeing the title message in the error log where I am trying to list files in a directory. I know it has to do with no index file in the driectory, but I just need to list files. I have this line in my httpd.conf file:
Options Indexes FollowSymLinks
Can someone suggest a way to enable file listing in a directory. Thanks

Check for other occurrences of the Options keyword, and take note of where they are. There's probably one somewhere in a matching <Directory> configuration block. grep -Ri Options /etc/httpd may be of help.
It's recommended to only allow Indexes in directories where you actually intend to allow directory listings, so it may be a good idea to add your own <Directory> block.

Related

Set IndexIgnore inside httpd.conf

I want to prevent directory file listing in all of my folders, so when a user types http://example.com/thisDoesNotExists/, the directory file listing do not show up.
According to a tutorial all I have to do is set IndexIgnore *
I try to set it in the httpd.conf, so I do
<IfModule mod_autoindex>
IndexIgnore *
</IfModule>
at the bottom of the httpd.conf.
It does not work. I get my 404errorPage.html without any styles.
How can I fix this? Thanks.
Disclaimer : I try to set this in httpd.conf and not htaccess because "You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance." According to this.
Your <IfModule> argument is wrong so the enclosing directive is never evaluated. The argument either needs to be the modules name (you can see
this in the corresponding LoadModule) or the main source filename.
Both "autoindex_module" and "mod_autoindex.c" work.
Here is another way to do it:
You should edit /etc/httpd/conf/httpd.conf, find the code block with
<Directory "/var/www/html">
Options Index FollowSymLinks
</Directory>
You should remove the Index in there then restart your httpd service by
sudo service httpd restart

Options +Indexes will not show filenames

How can I show file names in the directory listing on apache server.
I am using
Options +Indexes
I have also tried
Options Indexes FollowSymLinks
in the root but I am not able to see file names only an empty structure
There are 4-5 files of different names and extension available in the folder.
If you're unable to generate auto index even after dabbling with file permissions; it is generally all thanks to IndexIgnore directive.
Check your server settings, going one step above from the current htaccess at a time. See where you encounter it.

Load images outside apache directory

Well, I have a website in apache directory: /var/www/html. Previously I had all my web images in /var/www/html/media, so I used to put /media/imgX.jpgfor loading them. but now I need to put them in /mnt/imgs.
For some reason, using this path does not work the same way as before.
I think it has something to do with permissions using files from outside apache directory but I am not sure about it. Any idea?
The easiest way to add directories to Apache httpd is to use the "alias" module:
Alias /images "/mnt/imgs"
<Directory "/mnt/imgs>
Options Indexes
AllowOverride All
Require all granted
</Directory>
Once you have set up this, test it with: "yourdomain.com/images".
Of course:
The directory "/mnt/imgs" need the appropriate rights, so Apache Httpd can access it. Therefore you need to find out the group it runs with.
These files will be available to the public, if you dont secure them.
Once this is functional, remove the "indexes" line from the snippet above.

How can I get apache to list a folders contents?

How can I get Apache to display the contents of my folder and provide links to them? Similar to http://www.kernel.org/pub/linux/?
I don't have access to the Apache configuration, so I'm looking for something in the way of .htaccess or something I can do in just my home folder.
You have to use the option Indexes in the Apache configuration.
For instance, in the .htaccess file for your directory (if you can use those, and have sufficient privileges), you could put :
Options +Indexes
This functionality is provided by mod_autoindex, which has lots of options to allow fine-tuning of the generated output, btw
To get this working, that module must be loaded, and to be able to activate the option in an .htaccess file, you will need the admin of the server to give you some privileges (with the AllowOverride directive in the Apache's main config file, if I remember correctly -- well, your admin should know that better than me anyway ^^ )

Do you have to restart apache to make re-write rules in the .htaccess take effect?

I have pushed my .htaccess files to the production severs, but they don't work. Would a restart be the next step, or should I check something else.
A restart is not required for changes to .htaccess. Something else is wrong.
Make sure your .htaccess includes the statement
RewriteEngine on
which is required even if it's also present in httpd.conf. Also check that .htaccess is readable by the httpd process.
Check the error_log - it will tell you of any errors in .htaccess if it's being used.
Putting an intentional syntax error in .htaccess is a good check to make sure the file is being used -- you should get a 500 error on any page in the same directory.
Lastly, you can enable a rewrite log using commands like the following in your httpd.conf:
RewriteLog "logs/rewritelog"
RewriteLogLevel 7
The log file thus generated will give you the gory detail of which rewrite rules matched and how they were handled.
No:
Apache allows for decentralized management of configuration via special files placed inside the web tree. The special files are usually called .htaccess, but any name can be specified in the AccessFileName directive... Since .htaccess files are read on every request, changes made in these files take immediate effect...
From the apache documentation:
Most commonly, the problem is that AllowOverride is not set such that your configuration directives are being honored. Make sure that you don't have a AllowOverride None in effect for the file scope in question. A good test for this is to put garbage in your .htaccess file and reload. If a server error is not generated, then you almost certainly have AllowOverride None in effect.
Only if you have not added the mod_rewrite module to Apache.
You only need to restart Apache if you change any Apache ".conf" files.
I have the same issue and it seems PiedPiper post about AllowOverride were most helpful. Check your httpd.conf file for "AllowOverride" and make sure it is set to All.
In case of .htaccess restart is not required if it is not working probable reasons include.
AllowOverride May not be set which user can set inside httpd.conf or might have to contact server admin.
Check the file name of .htaccess it should be .htaccess not htaccess.txt see here for guide how to create one.
Try to use Options -Indexes or deny all kind of simple directive to see if it is working or not.
clear browser cache everytime if having rule for redirects or similar if previous redirect is cached it appears as if things are not working.
What's in your .htaccess? RewriteRules? Check that mod_rewrite is installed and enabled.
Other stuff? Try setting AllowOverride to 'all' on that directory.