You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Bo Berglund <bo...@gmail.com> on 2019/03/11 08:12:28 UTC

[users@httpd] How to block Apache2 from showing dir lists on Ubuntu 16.04 server...

I have an Ubuntu 16.04-5 server machine running as an offsite
subversion backup via nightly svnsync from the main server.
The main server is based in the office of my company and the backup in
my home.

Now I want to expand the server's usage to host a different website
for personal use also entering via the router on port 443 (using
https:// URLs).

I am creating a copy of what I have on my web hosting but running on
my home server.

I have gotten most of what I want to do working but for directory
listings...
If I enter an URL ending with a directory name Apache throws up a list
of all of the files inside the directory which is NOT what I want.
I have created a php command to create the display of the dir content
which works just fine on my webhosting server but not on the ubuntu 16
server.

This is what I have in my .htaccess file in this dir:

require valid-user
Options -Indexes
DirectoryIndex dirlist.php

But notwithstanding this Apache2 does not run the dirlist.php command
file to get the properly formatted list.

If I explicitly run the url ending with dirlist.php it works as
expected and I get my formatted directory list. But I want this to
happen also if the URL is just the directory itself.

So how can I make Apache NOT create the file list but instead run the
dirlist.php command?

I even went as far as editing the
/etc/apache2/sites-available/000-default.conf file and adding this to
the end of the directory block:

  <Directory "/var/www/html">
      AuthType Basic
      AuthName "Restricted Content"
      AuthUserFile /etc/apache2/private.htpasswd
      Require valid-user
      #Added to block dir listing and allow .htaccess to work
      AllowOverride All
      Options -Indexes
  </Directory>

Then sudo service apache2 restart

But nothing at all changes...


-- 
Bo Berglund
Developer in Sweden


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: How to block Apache2 from showing dir lists on Ubuntu 16.04 server...

Posted by "@lbutlr" <kr...@kreme.com>.
Bo Berglund <bo...@gmail.com> wrote:
> equire valid-user
> Options -Indexes
> DirectoryIndex dirlist.php

Does you main configuration have AllowOverride?

> I even went as far as editing the
> /etc/apache2/sites-available/000-default.conf file and adding this to
> the end of the directory block:

I didn't know that file, nor do I have the directory structure on my apache install (for me, sites-available is an nginx directory), but what does apachectl -S show as the path to the configuration files?

for example:

default server www.example.com (/usr/local/etc/apache24/extra/httpd-vhosts.conf:1)

-- 
all your snowflakes are urine and you can't even find the cat


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: How to block Apache2 from showing dir lists on Ubuntu 16.04 server...

Posted by Bo Berglund <bo...@gmail.com>.
On Mon, 11 Mar 2019 09:12:28 +0100, Bo Berglund
<bo...@gmail.com> wrote:

>If I enter an URL ending with a directory name Apache throws up a list
>of all of the files inside the directory which is NOT what I want.
>I have created a php command to create the display of the dir content
>which works just fine on my webhosting server but not on the ubuntu 16
>server.
>
>This is what I have in my .htaccess file in this dir:
>
>require valid-user
>Options -Indexes
>DirectoryIndex dirlist.php
>
>But notwithstanding this Apache2 does not run the dirlist.php command
>file to get the properly formatted list.
>
>If I explicitly run the url ending with dirlist.php it works as
>expected and I get my formatted directory list. But I want this to
>happen also if the URL is just the directory itself.
>
>So how can I make Apache NOT create the file list but instead run the
>dirlist.php command?

I did a workaround by changing the name of dirlist.php to index.php.
This makes Apache use this file as the renderer if the URL lacks the
file specification.
So this solves the problem for the directories which do have an
index.php inside.
But what to do for intermediate directories which are not supposed to
be shown at all? I REALLY want Apache to show a "Forbidden" page
rather than the list of files and dirs in the directory of the URL.

>I even went as far as editing the
>/etc/apache2/sites-available/000-default.conf file and adding this to
>the end of the directory block:
>
>  <Directory "/var/www/html">
>      AuthType Basic
>      AuthName "Restricted Content"
>      AuthUserFile /etc/apache2/private.htpasswd
>      Require valid-user
>      #Added to block dir listing and allow .htaccess to work
>      AllowOverride All
>      Options -Indexes
>  </Directory>
>
>Then sudo service apache2 restart
>

Question remains, why does this not work?

Note that I have not added any virtual hosts or anything, Apache is
straight out of the box except for Subversion and it has enabled the
default site /var/www/html, which is the one I am trying to get
working properly.

-- 
Bo Berglund
Developer in Sweden


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org