I keep hitting this error when trying to load up my Laravel application on an Ubuntu+Nginx server.

The user should visit app.example.com/my-app and it should load the contents of /var/www/app/my-app/public/index.php

[error] 9028#0: *15001 directory index of "/var/www/app/my-app/" is forbidden, client: xxx.xxx.xxx.xx, server: app.example.com, request: "GET /my-app/ HTTP/1.1", host: "app.example.com"

My nginx config is as follows:

  server_name app.example.com www.app.example.com;
  root /var/www/app;
  index index.php index.html index.htm;

  location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;

   location ~ \.php$
        #fastcgi_pass unix:/dev/shm/php-fpm-www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
            fastcgi_connect_timeout 60;
            fastcgi_send_timeout 180;
            fastcgi_read_timeout 180;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 8 256k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;

   location ~ /\.ht
        deny all;

   location /my-app/{
        alias /var/www/app/my-app/public/;
        try_files $uri $uri/ /public/index.php?$query_string;

        location ~ \.php$ {
           try_files $uri /index.php =404;
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           #fastcgi_index   index.php;
           #fastcgi_pass    unix:/var/run/php5-fpm.sock;
           fastcgi_index index.php;
           include         fastcgi_params;
           fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;


I've tried the following:

  • Set permissions chown -R www-data /var/www/app/my-app which didn't make any difference
  • Adjusting the alias and try_file directories which didn't change the error or assist
  • It's not clear if your application is working and you just see the error in your log or if you get some kind of error on the browser side. – Guido Vaccarella Feb 26 '15 at 10:35

The error is due to the $uri/ part of the try_files clause which instructs nginx to serve the content of the directory /var/www/app/my-app/. Directory listing is forbidden by default, you can enable it by adding autoindex on; to the location.

It's seems like the file /var/www/app/my-app/public/index.php does not exist.

  • unfortunately the same error displays with autoindex on; and after reloading nginx. /var/www/app/my-app/public/index.php definitely exists :/ – DT.DTDG Feb 24 '15 at 22:39
  • 1
    Hello, I'm having the same problem. Did you manage to fix your issue ? I'm using nested locations with alias directive instead of root, which must imply kind of request processing tricks by the way :/ – Stphane Jan 5 '16 at 10:19
  • 1
    afaik try_files $uri $uri/ index.php?args mean: try first to serve the request as a file, then try as a directory, finally serve index.php with args appended. So i dont understand why directory listing should be enabled. I only want my calls like site.com/test go under -eg- the file /var/www/app/my-app/test [as a file] if exists, otherwise in the dir /var/www/app/my-app/test/ otherwise /var/www/app/my-app/index.php?test – rollsappletree Mar 21 '18 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.