我使用 laravel 5.1 和 nginx / 1.8 这是我第一次使用Nginx Server
当我尝试访问laravel app主页时,路线运行良好
get('/', function () {
return view('welcome');
});
但是当我尝试访问任何其他页面时
get('/home', function () {
return 'Home Page';
// Or Blade Page
//return view('home');
});
Nginx返回
/etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
#root /usr/share/nginx/html;
root /var/www/nginx/html;
index index.php index.html index.htm;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
更新
/var/log/nginx/error.log
#3 / var / www / nginx / html / laravel / vendor / laravel / framework / src / Illuminate /Foundation/Exceptions/Handler.php(49): 独白\ Logger->误差(对象(Symfo 2016/01/11 22:59:38 [错误] 22510#0:* 31目录索引“/ var / www / nginx / html / laravel /”被禁止,客户端:127.0.0.1,服务器:_,请求: “GET / laravel / HTTP / 1.1”,主持人:“localhost”
注意:html/laravel
- > laravel 是应用名称
有什么建议吗?
答案 0 :(得分:1)
Root需要指向laravel安装的公用文件夹。如果您已将laravel安装到/var/www/nginx/html
,那么它应该是:
root /var/www/nginx/html/public