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

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

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

  1. server {
  2. listen 80;
  3. server_name phirater.test;
  4. root /var/www/html/public;
  5. index index.php index.htm index.html;
  6. charset utf-8;
  7. location / {
  8. try_files $uri $uri/ /index.php$is_args$args;
  9. }
  10. access_log /var/log/nginx/phirater.test-access.log;
  11. error_log /var/log/nginx/phirater.test-error.log error;
  12. error_page 404 /index.php;
  13. client_max_body_size 100m;
  14. location ~ \.php$ {
  15. include snippets/fastcgi-php.conf;
  16. fastcgi_intercept_errors on;
  17. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  18. fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  19. }
  20. location ~ /\.(?!well-known).* {
  21. deny all;
  22. }
  23. }

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:

  1. -rwxr-xr-x 1 1000 1000 1369 Jul 13 12:46 Dockerfile*
  2. drwxr-xr-x 13 1000 1000 4096 Nov 16 2022 app/
  3. -rwxr-xr-x 1 1000 1000 1635 Nov 16 2022 artisan*
  4. # ... (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

  1. server {
  2. listen 80;
  3. server_name phirater.test;
  4. root /var/www/html/public;
  5. index index.php index.htm index.html;
  6. charset utf-8;
  7. location / {
  8. try_files $uri $uri/ /index.php$is_args$args;
  9. }
  10. access_log /var/log/nginx/phirater.test-access.log;
  11. error_log /var/log/nginx/phirater.test-error.log error;
  12. error_page 404 /index.php;
  13. client_max_body_size 100m;
  14. location ~ \.php$ {
  15. include snippets/fastcgi-php.conf;
  16. fastcgi_intercept_errors on;
  17. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  18. fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
  19. }
  20. location ~ /\.(?!well-known).* {
  21. deny all;
  22. }
  23. }

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:

  1. -rwxr-xr-x 1 1000 1000 1369 Jul 13 12:46 Dockerfile*
  2. drwxr-xr-x 13 1000 1000 4096 Nov 16 2022 app/
  3. -rwxr-xr-x 1 1000 1000 1635 Nov 16 2022 artisan*
  4. -rw-rw-rw- 1 1000 1000 1321 Jul 13 12:45 bitbucket-pipelines.yml
  5. drwxr-xr-x 3 1000 1000 4096 Nov 16 2022 bootstrap/
  6. -rw-r--r-- 1 1000 1000 1419 Nov 16 2022 bower.json
  7. -rw-r--r-- 1 1000 1000 3393 Jun 14 05:19 composer.json
  8. -rw-r--r-- 1 1000 1000 410926 Jul 10 10:34 composer.lock
  9. drwxr-xr-x 2 1000 1000 4096 Jul 13 12:45 config/
  10. drwxr-xr-x 4 1000 1000 4096 Nov 16 2022 database/
  11. drwxr-xr-x 3 1000 1000 4096 Jul 5 02:24 docker-compose/
  12. -rw-rw-rw- 1 1000 1000 4114 Jul 13 12:45 gulpfile.js
  13. drwxr-xr-x 377 1000 1000 16384 Jun 8 09:26 node_modules/
  14. -rw-r--r-- 1 1000 1000 394 Jun 14 05:05 package.json
  15. -rw-r--r-- 1 1000 1000 724 Jul 18 06:42 phirater.test.conf
  16. -rw-r--r-- 1 1000 1000 5480 Jul 13 12:45 php-fpm.conf
  17. -rw-r--r-- 1 1000 1000 97 Nov 16 2022 phpspec.yml
  18. lrwxrwxrwx 1 1000 1000 18 Jun 13 06:31 phpunit -> vendor/bin/phpunit*
  19. -rw-r--r-- 1 1000 1000 1860 Jun 14 05:05 phpunit.xml
  20. drwxr-xr-x 8 1000 1000 4096 Nov 16 2022 public/
  21. drwxr-xr-x 5 1000 1000 4096 Nov 16 2022 resources/
  22. -rw-r--r-- 1 1000 1000 560 Nov 16 2022 server.php
  23. -rw-r--r-- 1 1000 1000 332 Jul 13 07:00 start-container.sh
  24. drwxr-xr-x 8 1000 1000 4096 Jul 13 10:01 storage/
  25. -rw-r--r-- 1 1000 1000 308 Jul 11 11:43 supervisord.conf
  26. drwxr-xr-x 7 1000 1000 4096 Jul 13 12:45 tests/
  27. 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上运行多个具有命名租户的实例,所以最简单的方法是覆盖默认配置。

  1. volumes:
  2. - phirater-l51/phirater.test.conf:/etc/nginx/conf.d/default.conf
  3. - 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.

  1. volumes:
  2. - phirater-l51/phirater.test.conf:/etc/nginx/conf.d/default.conf
  3. - 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:

确定