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,server:app.example.com,request:“GET / my-app / HTTP / 1.1“,主机:”app.example.com“

我的nginxconfiguration如下:

 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没有什么区别
  • 调整没有改变错误或帮助的aliastry_file目录

错误是由于try_files子句的$uri/部分,它指示nginx提供/ var / www / app / my-app /目录的内容。 目录列表默认是禁止的,你可以通过添加autoindex on;来启用它autoindex on; 到的位置。

好像文件/var/www/app/my-app/public/index.php不存在。