0
votes

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.

1
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
Because I want to avoid tuning PHP rather take the base default image and get all extensions installed and configured.Raheel
@DavidMaze this is how i am running container docker run -p 8080:80 -v /path/to/project:/var/www/html test-phpRaheel
The ls -al you posted is done from your host or inside your container ?Michée Lengronne
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

1 Answers

1
votes

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.