Laravel 5 - Nginx/PHP 配置问题
Laravel 5 - Nginx/PHP config issue
我遇到一个问题,当我转到 /public 目录时,它正常显示 Laravel 应用程序,但导航到任何其他页面会导致它显示
未指定输入文件。
我正在使用 PHP 5.5.9 FPM 的 Nginx 服务器。
我在过去 4 个小时左右的时间里搜索了 google,查看了每个教程和 Whosebug 页面以寻找 Laravel 中的重写问题,但是它们都产生了相同的结果。
我什至将所有文件和文件夹设置为 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 ^/(.+)/$ / 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;
}
}
错误 "No input files specified" 几乎总是与发送到 php 的错误路径有关。
查看您的 'last config tried' 我可以看到 fastcgi_param SCRIPT_FILENAME
未在您的 php 位置定义。您应该首先在位置定义它:
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 :解决方案是根指令应该指向 Laravel public 文件夹,在这种情况下 /usr/share/sites/base/public
.
我遇到一个问题,当我转到 /public 目录时,它正常显示 Laravel 应用程序,但导航到任何其他页面会导致它显示
未指定输入文件。
我正在使用 PHP 5.5.9 FPM 的 Nginx 服务器。
我在过去 4 个小时左右的时间里搜索了 google,查看了每个教程和 Whosebug 页面以寻找 Laravel 中的重写问题,但是它们都产生了相同的结果。
我什至将所有文件和文件夹设置为 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 ^/(.+)/$ / 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;
}
}
错误 "No input files specified" 几乎总是与发送到 php 的错误路径有关。
查看您的 'last config tried' 我可以看到 fastcgi_param SCRIPT_FILENAME
未在您的 php 位置定义。您应该首先在位置定义它:
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 :解决方案是根指令应该指向 Laravel public 文件夹,在这种情况下 /usr/share/sites/base/public
.