Directory index of "/var/www/html/" is forbidden

huangapple go评论59阅读模式
英文:

Directory index of "/var/www/html/" is forbidden

问题

I am using docker compose to up my container which works fine but when I try to go to the http://localhost:8080/ I get the following error:

> 2023/07/18 07:22:07 [error] 12#12: *6 directory index of
> "/var/www/html/" is forbidden, client: 172.31.0.1, server: _, request:
> "GET / HTTP/1.1", host: "localhost:8080"
> 172.31.0.1 - - [18/Jul/2023:07:22:07 +0000] "GET / HTTP/1.1" 403 196 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
> Gecko) Chrome/114.0.0.0 Safari/537.36"

And here is my nginx config file named: phirater.test.conf

server {
    listen 80;
    server_name phirater.test;
    root /var/www/html/public;

    index index.php index.htm index.html;

    charset utf-8;

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

    access_log /var/log/nginx/phirater.test-access.log;
    error_log  /var/log/nginx/phirater.test-error.log error;

    error_page 404 /index.php;

    client_max_body_size 100m;

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_intercept_errors on;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

    location ~ /\.(?!well-known).* {
            deny all;
    }
}

When I try to hit the following: http://localhost:8080/composer.json it displays the content of the files but http://localhost:8080 return with the error mentioned above.
What I am doing wrong here?

User permissons are like this inside the container:

-rwxr-xr-x   1 1000 1000   1369 Jul 13 12:46 Dockerfile*
drwxr-xr-x  13 1000 1000   4096 Nov 16  2022 app/
-rwxr-xr-x   1 1000 1000   1635 Nov 16  2022 artisan*
# ... (other file permissions)

I tried the solution on various similar question here on SO but none worked.

英文:

I am using docker compose to up my container which works fine but when I try to go to the http://localhost:8080/ I get the following error:

> 2023/07/18 07:22:07 [error] 12#12: *6 directory index of
> "/var/www/html/" is forbidden, client: 172.31.0.1, server: _, request:
> "GET / HTTP/1.1", host: "localhost:8080"
> 172.31.0.1 - - [18/Jul/2023:07:22:07 +0000] "GET / HTTP/1.1" 403 196 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
> Gecko) Chrome/114.0.0.0 Safari/537.36"

And here is my nginx config file named: phirater.test.conf

server {
    listen 80;
    server_name phirater.test;
    root /var/www/html/public;

    index index.php index.htm index.html;

    charset utf-8;

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

    access_log /var/log/nginx/phirater.test-access.log;
    error_log  /var/log/nginx/phirater.test-error.log error;

    error_page 404 /index.php;

    client_max_body_size 100m;

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_intercept_errors on;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }

    location ~ /\.(?!well-known).* {
            deny all;
    }
}

When I try to hit the following: http://localhost:8080/composer.json it displays the content of the files but http://localhost:8080 return with the error mentioned above.
What I am doing wrong here?

User permissons are like this inside the container:

-rwxr-xr-x   1 1000 1000   1369 Jul 13 12:46 Dockerfile*
drwxr-xr-x  13 1000 1000   4096 Nov 16  2022 app/
-rwxr-xr-x   1 1000 1000   1635 Nov 16  2022 artisan*
-rw-rw-rw-   1 1000 1000   1321 Jul 13 12:45 bitbucket-pipelines.yml
drwxr-xr-x   3 1000 1000   4096 Nov 16  2022 bootstrap/
-rw-r--r--   1 1000 1000   1419 Nov 16  2022 bower.json
-rw-r--r--   1 1000 1000   3393 Jun 14 05:19 composer.json
-rw-r--r--   1 1000 1000 410926 Jul 10 10:34 composer.lock
drwxr-xr-x   2 1000 1000   4096 Jul 13 12:45 config/
drwxr-xr-x   4 1000 1000   4096 Nov 16  2022 database/
drwxr-xr-x   3 1000 1000   4096 Jul  5 02:24 docker-compose/
-rw-rw-rw-   1 1000 1000   4114 Jul 13 12:45 gulpfile.js
drwxr-xr-x 377 1000 1000  16384 Jun  8 09:26 node_modules/
-rw-r--r--   1 1000 1000    394 Jun 14 05:05 package.json
-rw-r--r--   1 1000 1000    724 Jul 18 06:42 phirater.test.conf
-rw-r--r--   1 1000 1000   5480 Jul 13 12:45 php-fpm.conf
-rw-r--r--   1 1000 1000     97 Nov 16  2022 phpspec.yml
lrwxrwxrwx   1 1000 1000     18 Jun 13 06:31 phpunit -> vendor/bin/phpunit*
-rw-r--r--   1 1000 1000   1860 Jun 14 05:05 phpunit.xml
drwxr-xr-x   8 1000 1000   4096 Nov 16  2022 public/
drwxr-xr-x   5 1000 1000   4096 Nov 16  2022 resources/
-rw-r--r--   1 1000 1000    560 Nov 16  2022 server.php
-rw-r--r--   1 1000 1000    332 Jul 13 07:00 start-container.sh
drwxr-xr-x   8 1000 1000   4096 Jul 13 10:01 storage/
-rw-r--r--   1 1000 1000    308 Jul 11 11:43 supervisord.conf
drwxr-xr-x   7 1000 1000   4096 Jul 13 12:45 tests/
drwxr-xr-x  81 1000 1000   4096 Jul  5 05:22 vendor/

I tried the solution on various similar question here on SO but none worked.

答案1

得分: 1

您正在使用一个具有命名主机的配置,因此您需要确保请求的URL与之匹配,即http://phirater.test:8080/

处理您的http://localhost:8080/请求的服务器是默认服务器,这就是为什么错误提到了/var/www/html而不是/var/www/html/public

您可以通过编辑您的hosts文件来使用命名主机,但我建议,因为您不太可能在nginx上运行多个具有命名租户的实例,所以最简单的方法是覆盖默认配置。

volumes:
  - phirater-l51/phirater.test.conf:/etc/nginx/conf.d/default.conf
  - phirater-l51:/var/www/html
英文:

You're using a named host so you'd need the request URL to match, ie http://phirater.test:8080/.

The server handling your http://localhost:8080/ request is the default one which is why the error mentions /var/www/html and not /var/www/html/public.

You can use your named host by editing your hosts file, however I recommend since it's unlikely you're running nginx with multiple named tenants to simply overwrite the default config.

volumes:
  - phirater-l51/phirater.test.conf:/etc/nginx/conf.d/default.conf
  - phirater-l51:/var/www/html

huangapple
  • 本文由 发表于 2023年7月18日 15:37:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710480.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定