【发布时间】:2016-10-26 05:18:54
【问题描述】:
我在 Laravel 5.1 上建立了一个网站。它会在除主页之外的任何页面上引发 404 错误。但是,当我在 URL 中添加 index.php 时,它可以工作。我的网站在 Ubuntu 机器上运行,Nginx 作为 Web 服务器。
加载正常: mysite.com/index.php/dashboard
提供 404: mysite.com/dashboard
我在公用文件夹中的 .htaccess:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
感谢您的宝贵时间,如果能提供任何帮助,我将不胜感激。
编辑:
这是我的 Nginx 配置文件:
server {
server_name mysite.com;
return 301 $scheme://www.mysite.com$request_uri;
}
server {
listen 80;
server_name www.mysite.com;
# note that these lines are originally from the "location /" block
root /usr/share/web/site/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/web/html;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_max_temp_file_size 0;
fastcgi_buffer_size 4K;
fastcgi_buffers 64 4k;
include fastcgi_params;
}
}
【问题讨论】: