【问题标题】:Laravel 5 - Nginx/PHP config issueLaravel 5 - Nginx/PHP 配置问题
【发布时间】:2015-02-17 06:06:10
【问题描述】:

我遇到了一个问题,当我转到 /public 目录时,它会正常显示 Laravel 应用程序,但导航到任何其他页面会导致它显示

没有指定输入文件。

我正在使用带有 PHP 5.5.9 FPM 的 Nginx 服务器。

在过去的 4 个小时左右,我搜索了谷歌,查看了 Laravel 中重写问题的每个教程和 stackoverflow 页面,但是它们都产生了相同的结果。

我什至将所有文件和文件夹设置为 777,这样我就可以查看是否是某种权限问题。我检查了 Laravel 配置,一切就绪,我不知道出了什么问题。

谁能指出我正确的方向?

我尝试的最后一个配置如下:

server {
    listen 80 default_server;

    root /usr/share/sites/base;
    index index.php
    server_name localhost;
    location / {
            try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include fastcgi_params;
    }
}

我还尝试了很多其他方法,例如:

server {

            listen          80;
            server_name     domain.com;

            root            /usr/share/sites/base;
            index           index.php;


            location / {

                    try_files $uri $uri/ /index.php?$query_string;

            }

    if (!-d $request_filename) {

            rewrite ^/(.+)/$ /$1 permanent;

    }


    location ~* \.php$ {

            # Server PHP config.
            fastcgi_pass                    unix:/var/run/php5-fpm.sock;
            fastcgi_index                   index.php;
            fastcgi_split_path_info         ^(.+\.php)(.*)$;

            include                         /etc/nginx/fastcgi_params;
            fastcgi_param                   SCRIPT_FILENAME $document_root$fastcgi_script_name;

    }

    location ~ /\.ht {
            deny all;

    }

    }

【问题讨论】:

    标签: php ubuntu laravel nginx


    【解决方案1】:

    “未指定输入文件”错误几乎总是与错误的路径被发送到 php.ini 相关。

    查看您的“上次尝试的配置”,我可以看到 fastcgi_param SCRIPT_FILENAME 未在您的 php 位置中定义。您应该首先在 location 中定义它:

    location ~ \.php$ {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
    }
    

    此外,您说您可以访问该应用程序,因此这意味着 index.php 正在工作,但在您更改页面时却没有。所以问题也应该来自/index.php?$args。实际上,如果我尝试访问 yourserver.com/test 并且如果“test”不是根路径中的文件,则使用此行 nginx 将尝试请求 /index.php? (我有这个问题)。你应该只尝试/index.php

    EDIT:解决方案是 root 指令应该指向 Laravel 公用文件夹,在这种情况下是 /usr/share/sites/base/public

    【讨论】:

    • 啊,您的回答让我意识到我需要在根目录上指定 /public 才能使其正常工作。感谢您的帮助!
    • 哦,我以为 'base' 是你的 Laravel 公用文件夹,没想到!你还有什么改变吗?
    • 我决定使用两者中较长的配置,不确定第一个是否有效。
    • '/index.php?$query_string' 根据 Laravel 文档,对于漂亮的 url 来说是必需的。 (尽管我确实使用了不需要这条线才能正常工作的 Laravel 应用程序)。我们可以看到 SCRIPT_FILENAME 是在 php 位置定义的。根据应用程序,可能需要“fastcgi_index index.php”,但如果您在 try_files 指令中定义 /index.php,它绝对有可能在没有它的情况下工作。如果 Apache doc root 与 Nginx 一致,则需要 \.ht 位置。它将阻止 .htaccess 文件。在我看来,if 语句就像“保证”
    猜你喜欢
    • 2012-03-17
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 1970-01-01
    • 2017-07-25
    相关资源
    最近更新 更多