1

I am using the following file copied at /etc/nginx/conf.d/default.conf

server {
    listen 80;
    root /var/www/html/public;
    index index.php index.htm index.html;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;

        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000;
    }

    location ~ \.php$ {
        return 404;
    }
}

It is giving me the following error in log

*7 directory index of "/var/www/html/" is forbidden, client: 172.17.0.1, server: _, request: "GET / HTTP/1.1", host: "localhost:8080"

Trying to debug but no clue.

My files are under www-data:www-data

enter image description here

I am using a docker image from php:7.4-fpm if it is related.

FROM php:7.4-fpm

WORKDIR /var/www/html

RUN export DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y nginx procps

COPY infrastructure/nginx/default.conf /etc/nginx/conf.d/default.conf

COPY infrastructure/entrypoint.sh /etc/entrypoint.sh

EXPOSE 80

ENTRYPOINT ["sh", "/etc/entrypoint.sh"]

Thanks for help.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Raheel
  • 8,716
  • 9
  • 60
  • 102
  • How are you running the image? If your container should be running Nginx, why did you base it off of a PHP-FPM image? – David Maze Aug 06 '20 at 12:38
  • Because I want to avoid tuning PHP rather take the base default image and get all extensions installed and configured. – Raheel Aug 06 '20 at 12:40
  • @DavidMaze this is how i am running container `docker run -p 8080:80 -v /path/to/project:/var/www/html test-php` – Raheel Aug 06 '20 at 12:40
  • The `ls -al` you posted is done from your host or inside your container ? – Michée Lengronne Aug 06 '20 at 12:44
  • I think it is due to the fact that your `www-data` from your host does not have the same `uid:gid` than the one from your container. – Michée Lengronne Aug 06 '20 at 12:45
  • @MichéeLengronne inside container. – Raheel Aug 06 '20 at 12:45
  • Do you have an index file inside of your public folder? – aynber Aug 06 '20 at 12:47
  • Ok, so forget my previous comment. In your `nginx.conf` what is the `user` directive ? – Michée Lengronne Aug 06 '20 at 12:47
  • @aynber yes its there. – Raheel Aug 06 '20 at 12:48
  • @MichéeLengronne `user www-data;` this is from `/etc/nginx/nginx.conf`. – Raheel Aug 06 '20 at 12:49
  • Does this issue help you ? https://stackoverflow.com/questions/19285355/nginx-403-error-directory-index-of-folder-is-forbidden – Michée Lengronne Aug 06 '20 at 12:51
  • @MichéeLengronne nope, just tried it again with the same configuration as mentioned in that answer, still 403 – Raheel Aug 06 '20 at 12:56
  • 1
    The error message means that there is no `index.html` file in `/var/www/html`. The configuration file in your question sets the root to `/var/www/html/public` which means that it's not the configuration that Nginx is using. Use `nginx -T` (uppercase `T`) to view the entire configuration that Nginx is reading. – Richard Smith Aug 06 '20 at 13:59
  • @RichardSmith Yes that was the issue. There was a default configuration set in `/etc/nginx/nginx.conf` that was being executred`. nging -T helped to identify. THanks – Raheel Aug 06 '20 at 14:05

1 Answers1

1

It says "directory index...is forbidden" NOT that is does not have permission. If you were to provide the URL of one of the files, e.g. http://example.com/composer.json , nginx should happily return the content to your browser. If you explicitly want to browse the files in a directory then this must be explicitly enabled in the nginx config.

symcbean
  • 47,736
  • 6
  • 59
  • 94