Disable directory listing on apache; but access to individual files should be allowed

前端 未结 5 1846
夕颜
夕颜 2021-01-31 19:28

I do not want to use .htaccess. How should I change my Directory attributes?


   ServerName abc.com
   DocumentRoot /usr/share/uploads
           


        
相关标签:
5条回答
  • 2021-01-31 19:41

    The @Deepak solution did not worked for me. This one did:

    In the main apace configuration /etc/apache2/httpd.conf just add:

    <Directory />
            Options FollowSymLinks
            AllowOverride All
    </Directory>
    

    And it will work for all of you domains and subdomains. Without .htaccess file.

    0 讨论(0)
  • 2021-01-31 19:43

    The easiest way would be to put an empty index.html (or whatever you apache is configured to deliver by default) inside that directory. This is not a real solution but a very simple workaround. The user browsing that directory would just see a blank white page.

    Further you could use a script (like index.php) wich emulates the directory-listing and only shows some special files.

    0 讨论(0)
  • 2021-01-31 19:45

    I really couldnt find a direct answer on internet ; even on apache documentation. Finally, could find the solution through few iterations; we need to use Options and the value should NOT contain Indexes.

    <Directory "/usr/share/uploads">
            Options Includes FollowSymLinks MultiViews
            AllowOverride None
             Order allow,deny
          Allow from all
       </Directory>
    
    0 讨论(0)
  • 2021-01-31 19:56

    All done above, but the directory info is still coming up? If you use index.php, rather than index.html, Check the following:

    <IfModule dir_module>
        DirectoryIndex index.php
    </IfModule>
    
    0 讨论(0)
  • 2021-01-31 20:05

    If you are using Debian/Ubuntu, just go to terminal and type

    sudo a2dismod autoindex
    sudo service apache2 restart
    

    If you are using Centos/Fedora, just do:

    mv /etc/httpd/conf.d/autoindex.conf /etc/httpd/conf.d/autoindex.bkp
    /etc/init.d/httpd restart
    

    And similarly in other OS or distros...

    This should disable the apache module that makes those fancy (normally useless and a security problem) directory listings. Also, as a bonus, you earn a bit of performance :-)

    0 讨论(0)
提交回复
热议问题