【问题标题】:Laravel shows me 'index of /' pageLaravel 向我显示“/”页面的索引
【发布时间】:2015-03-15 00:15:16
【问题描述】:

所以,我正在尝试找出 Laravel。我将它安装在 Nginx 服务器上并更改了配置文件 - 我将其粘贴在下面。但是,当我访问该网址时,它会向我显示一个 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;
        }
}

【问题讨论】:

    标签: php laravel nginx


    【解决方案1】:

    我不使用 nginx,但根据您的屏幕截图,您的 web 根文件夹设置不正确。如果我正确读取了该配置文件,则您已将 Web 根目录设置为

    /var/www/website.com/htdocs/
    

    当你想要它设置为

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

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

    【讨论】:

    • 那行得通。现在我得到了一个空白屏幕:P
    • @User183849481 空白屏幕通常意味着 PHP 或 Apache 网络服务器错误。暂时将 Laravel 置于调试模式,以便输出错误,和/或扫描您的错误日志。
    • 我是 Laravel 的菜鸟,所以不要介意我问:我该怎么做?
    • @User in app/config/app.php'debug' 更改为 true,或者只查看 app/storage/logs/laravel.log 中的最后一个错误。
    【解决方案2】:

    @User183849481

    在你的 nginx 配置文件中将 fastcgi_pass unix:/tmp/php.socket; 更改为 fastcgi_pass 127.0.0.1:9000;。 这将解决您的问题,因为 nginx Web 服务器无法将请求传递给 php 处理器。 它显示空白屏幕。

    【讨论】:

    • 运行此命令netstat -apn | grep php-fpm。它会告诉你哪些端口php-fpm 进程正在运行。相应地在 fastcgi_pass 指令前面的 nginx 配置中更改您的端口。
    猜你喜欢
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 2020-04-12
    相关资源
    最近更新 更多