php - Laravel 显示 'index of/' 页面

标签 php laravel nginx

所以,我正在尝试了解 Laravel。我将它安装在 Nginx 服务器上并更改了配置文件 - 我将其粘贴在下面。但是,当我访问该 url 时,它会显示一个 Index of/ 页面,如下所示:http://imgur.com/JQiBmz4

server {
    server_name website.com www.website.com;
    root /var/www/website.com/htdocs/;

    index index.php index.html;

    #browse folders if no index file
        autoindex on; 

    # serve static files directly
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
        access_log off;
        expires max;
    }

    # removes trailing slashes (prevents SEO duplicate content issues)
    if (!-d $request_filename)
    {
        rewrite ^/(.+)/$ /$1 permanent;
    }

    # enforce NO www
    if ($host ~* ^www\.(.*))
    {
        set $host_without_www $1;
        rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
    }


    # canonicalize codeigniter url end points
    # if your default controller is something other than "welcome" you should change the following
    if ($request_uri ~* ^(/lobby(/index)?|/index(.php)?)/?$)
    {
        rewrite ^(.*)$ / permanent;
    }

    # removes trailing "index" from all controllers
    if ($request_uri ~* index/?$)
    {
        rewrite ^/(.*)/index/?$ /$1 permanent;
    }

    # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php?/$1 last;
        break;
    }

    # catch all
    error_page 404 /index.php;

        location ~ \.php$ {
        try_files $uri =404;
                fastcgi_pass  unix:/tmp/php.socket;
                fastcgi_index index.php;
                #include fastcgi_params;
                include /etc/nginx/fastcgi_params;
        }
}

最佳答案

我不使用 nginx,但根据您的屏幕截图,您的网络根文件夹设置似乎不正确。如果我正确地读取了那个配置文件,那么你已经将你的网络根目录设置为

/var/www/website.com/htdocs/

当你想要它设置为

/var/www/website.com/htdocs/public

也就是说,普通 Laravel 应用程序附带的 public 文件夹应该是 Web 服务器看到的文件夹。其他文件夹应该可以通过网络访问。

关于php - Laravel 显示 'index of/' 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25492737/

相关文章:

php - openssl_pkey_export 和 "cannot get key from parameter 1"

laravel - 如何在MathML中将Elasticsearch用于索引公式?

laravel 和请求验证

angularjs - 使用基于 token 的身份验证时处理数据的最佳方法是什么

node.js - 代理到 Node/Express 上游时不常见的 NGINX 错误/超时(连接到上游时上游超时)

php - 根据所做的选择选择框加载

javascript - 如何引用 php 文件中未在 <form> 中提及的元素

php - 在 PHP 中搜索数据库 从单列到所有

在 nginx 中将/foo.html重定向到/foo但不是/to/index

php - 我如何使用 Nginx 列出目录及其文件?