Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; server { listen 80; server_name localhost; root /var/www/html; location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; if (!-f $document_root$fastcgi_script_name) { return 404; root /var/www/html; fastcgi_pass web_fpm:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.+)$;

It work well if I create index.html . But if I want to access index.php , I have a 403 error and the following log in docker-compose:

web_front_1  | 2016/05/12 12:59:44 [error] 7#7: *1 directory index of "/var/www/html/" is forbidden, client: IP, server: localhost, request: "GET / HTTP/1.1", host: "IP"
web_front_1  | IP - - [12/May/2016:12:59:44 +0000] "GET / HTTP/1.1" 403 197 "-" "Mozilla/5.0 (Linux; Android 6.0.1; A0001 Build/MMB29X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.105 Mobile Safari/537.36"

I've tried advices found in other Q&A (like here), but I can't get it to work.

From your log I see that you're trying to access / location. And I don't see entries in your nginx config which will intercept such request. So I assume following in that case:

  • for requests to / nginx tries serve static files from specified root;
  • by-default index file is index.html and you don't override this setting. So thats why it starts to work fine when you add index.html;
  • by-default directory index is forbidden and this is what nginx tries to do in case index file is missing. So you're getting 403 response and I clearly see that in your log.
  • Most likely it should start to work if you make request with /index.php

    What you should do to make request to site root work is add something like that:

    location / {
      root      /var/www/html;
      try_files $uri /index.php$is_args$args;
    

    Keep in mind that instead of /index.php$is_args$args in your case should be something specific to script/framework you're using.

    I had the same error, but my problem was permission on the main folder. The html folder itself had no permission. In my case running the command "chmod -R 755" solved. With "-R" I also made sure that all the subdirectories had the same permission (Note that this may cause a security problem depending on your case, my server is a test server so I didn't bother).

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.