Ubuntu + Nginx: 「/var/www/app/my-app/」のディレクトリ インデックスは禁止されています

Ubuntu + Nginx: 「/var/www/app/my-app/」のディレクトリ インデックスは禁止されています

Ubuntu + Nginx サーバーで Laravel アプリケーションをロードしようとすると、このエラーが発生し続けます。

ユーザーは訪問しapp.example.com/my-app、次のコンテンツを読み込む必要があります。/var/www/app/my-app/public/index.php

[エラー] 9028#0: *15001 ディレクトリ インデックス "/var/www/app/my-app/" は禁止されています。クライアント: xxx.xxx.xxx.xx、サーバー: app.example.com、リクエスト: "GET /my-app/ HTTP/1.1"、ホスト: "app.example.com"

私の nginx 設定は次のとおりです:

server
{
  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_pass 127.0.0.1:7777;
        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_pass 127.0.0.1:7777;
           fastcgi_index index.php;
           include         fastcgi_params;
           fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
  }

}

私は次のことを試しました:

  • 権限を設定してchown -R www-data /var/www/app/my-appも何の違いもなかった
  • エラーやアシストを変更しなかったディレクトリaliasを調整するtry_file

答え1

エラーは、nginx にディレクトリ /var/www/app/my-app/ のコンテンツを提供するよう指示する try_files 句の一部が原因で発生します。ディレクトリの一覧表示はデフォルトでは禁止されていますが、場所に$uri/追加することで有効にすることができます。autoindex on;

/var/www/app/my-app/public/index.php ファイルが存在しないようです。

関連情報