LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-23-2018, 04:24 AM   #1
Epic555
LQ Newbie
 
Registered: Sep 2017
Posts: 10

Rep: Reputation: Disabled
Prevent directory listing (browsing)?


Hi, how to prevent directory listing (directory browsing) of "https://myzabbix.com/icons/" web-page?
I found 2 methods how to do it on Apache on CentOS, but it doesn't work:
1) In httpd.conf in section <Directory "/var/www/html"> i removed a word "Indexes" or tried to write "-Indexes" in "Options FollowSymLinks", also i put "AllowOverride All" and restarted Apache.
2) I created .htaccess file in /var/www/html/ and put "Options -Indexes" in it.
But it didnt help.
What is wrong?
 
Old 02-23-2018, 05:18 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Originally Posted by Epic555 View Post
Hi, how to prevent directory listing (directory browsing) of "https://myzabbix.com/icons/" web-page?
I found 2 methods how to do it on Apache on CentOS, but it doesn't work:
1) In httpd.conf in section <Directory "/var/www/html"> i removed a word "Indexes" or tried to write "-Indexes" in "Options FollowSymLinks", also i put "AllowOverride All" and restarted Apache.
2) I created .htaccess file in /var/www/html/ and put "Options -Indexes" in it.
But it didnt help.
What is wrong?
FYI /icons is an Alias to /var/www/icons, so you need to toggle Indexes in that directory stanza in apache config file

Regards
 
Old 02-23-2018, 08:57 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
You can put a blank index.html file in the directory to prevent listing
 
Old 02-23-2018, 01:34 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
The syntax is
Code:
<Directory "/var/www/html">
   Options -Indexes
</Directory>
in httpd.conf

to allow the .htaccess to work, add
Code:
 AllowOverride Options
to the directory container.

The above will suppress directory listings in all directories under /var/www/html

To suppress a specific directory only, create a <Directory ...> container for that directory with the Options directive inside it.

Pretty sure the syntax is the same in an .htaccess file...the Options directive inside a Directory container.
 
Old 02-25-2018, 10:24 PM   #5
Epic555
LQ Newbie
 
Registered: Sep 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
FYI /icons is an Alias to /var/www/icons, so you need to toggle Indexes in that directory stanza in apache config file
I did this, but it didn't help.

Quote:
Originally Posted by scasey View Post
The syntax is
Code:
<Directory "/var/www/html">
   Options -Indexes
</Directory>
in httpd.conf
to allow the .htaccess to work, add
Code:
 AllowOverride Options
to the directory container.
It didn't help too.

I created a file zabbix_icons_dir.conf in /etc/httpd/conf.d. with code
<Directory "/usr/share/httpd/icons">
Require all denied
</Directory>
It helped.
 
Old 02-25-2018, 10:37 PM   #6
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by Epic555 View Post
I created a file zabbix_icons_dir.conf in /etc/httpd/conf.d. with code
<Directory "/usr/share/httpd/icons">
Require all denied
</Directory>
It helped.
Well yes, that would, but that's preventing anyone from using any of the files in that directory, not just suppressing the directory listing. If that's ok (if you don't need to use any of those files on any web page), then you're done. Otherwise, add
Code:
Options -Indexes
to that container:
Code:
<Directory "/usr/share/httpd/icons">
   Options -Indexes
   Require all granted
</Directory>
to allow access to the files but still suppress the directory listings.

As I said earlier:
Quote:
Originally Posted by scasey View Post
To suppress a specific directory only, create a <Directory ...> container for that directory with the Options directive inside it.

Last edited by scasey; 02-25-2018 at 10:40 PM.
 
Old 02-25-2018, 11:03 PM   #7
Epic555
LQ Newbie
 
Registered: Sep 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
add
Code:
Options -Indexes
to that container:
Code:
<Directory "/usr/share/httpd/icons">
   Options -Indexes
   Require all granted
</Directory>
Do i need to add this to the httpd.conf or .htaccess?
I added it to the httpd.conf, but it didn't help.
 
Old 02-25-2018, 11:26 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by Epic555 View Post
Do i need to add this to the httpd.conf or .htaccess?
I added it to the httpd.conf, but it didn't help.
Quote:
Originally Posted by Epic555 View Post
I created a file zabbix_icons_dir.conf in /etc/httpd/conf.d. with code
<Directory "/usr/share/httpd/icons">
Require all denied
</Directory>
It helped.
Add it to the Directory container you created in zabbix_icons_dir.conf in /etc/httpd/conf.d.

PS You are restarting apache after every change, right?
 
Old 02-25-2018, 11:37 PM   #9
Epic555
LQ Newbie
 
Registered: Sep 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
Add it to the Directory container you created in zabbix_icons_dir.conf in /etc/httpd/conf.d.

PS You are restarting apache after every change, right?
Sorry, i didn't understand exactly your previous reply, i read it again and got it).

When i added code to the /etc/httpd/conf.d/zabbix_icons_dir.conf, it works.
Yes of course, i restart httpd after every change.

Last edited by Epic555; 02-25-2018 at 11:41 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache2: Prevent Directory Listing nick1 Linux - Software 10 02-21-2014 04:40 PM
vsftpd: How to prevent from listing parent directory (not chroot) Skelray Linux - Server 3 10-27-2012 06:25 AM
How can I prevent a user from seeing a file in a directory listing? nuspieds Linux - Newbie 4 05-03-2011 11:38 AM
How to prevent directory browsing in ftp, but still download from folder rpfrimmer Linux - Security 3 07-29-2007 02:07 AM
how to prevent directory listing in apache ? chuck77 Linux - General 7 12-21-2001 03:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration