Laravel 向我显示“/”页面的索引

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25492737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:59:55  来源:igfitidea点击:

Laravel shows me 'index of /' page

phplaravelnginx

提问by User183849481

So, I'm trying to figure out Laravel. I installed it on the Nginx server and changed the config file - I pasted it below. However, when I visit the url, it shows me an Index of /page like this: http://imgur.com/JQiBmz4

所以,我想弄清楚 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 ^/(.+)/$ / permanent;
    }

    # enforce NO www
    if ($host ~* ^www\.(.*))
    {
        set $host_without_www ;
        rewrite ^/(.*)$ $scheme://$host_without_www/ 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/?$ / permanent;
    }

    # unless the request is for a valid file (image, js, css, etc.), send to bootstrap
    if (!-e $request_filename)
    {
        rewrite ^/(.*)$ /index.php?/ 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;
        }
}

回答by Alan Storm

I don't use nginx, but based on your screenshot it looks like you have the web root folder set incorrectly. If I'm reading that config file correctly, you've set your web root to

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

/var/www/website.com/htdocs/

When you want it set to

当你想要它设置为

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

That is, the publicfolder that ships with a stock Laravel application should be the folder the web server sees. The other folders should notbe web accessible.

也就是说,publicLaravel 应用程序附带的文件夹应该是 Web 服务器看到的文件夹。其他文件夹应该不会是网络访问。

回答by Harshad Yeola

@User183849481

@User183849481

change fastcgi_pass unix:/tmp/php.socket;to fastcgi_pass 127.0.0.1:9000;in your nginx conf. This will solve your problem as nginx web server could not pass requests to the php processor. It was showing blank screen.

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