【问题标题】:Laravel 5.4 Nginx 1.10 PHP 7 route except "/" are returning 404Laravel 5.4 Nginx 1.10 PHP 7 路由除了“/”返回 404
【发布时间】:2017-11-15 23:16:33
【问题描述】:
这是我的配置
server {
listen 80;
listen [::]:80;
server_name mysite.com;
root /var/www/site/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files \$uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)\$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
}
我的站点的根目录可以访问,所有其他路由都返回 404 错误。
提前致谢。
干杯。
【问题讨论】:
标签:
php
laravel
nginx
http-status-code-404
【解决方案1】:
一些变化...我运行 php 7.1 ...
位置...试试 /index.php?$query_string;如下例所示……
server {
listen 80;
listen [::]:80;
server_name mysite.com;
root /var/www/site/public;
index index.php index.html;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
【解决方案2】:
确保您的 PHP-FPM 运行与 nginx 相同的用户
即sudo vim /etc/php/7.1/fpm/pool.d/www.conf
...
user = nginx
group = nginx
...
listen.owner = nginx
listen.group = nginx
...
然后sudo systemctl restart php7.1-fpm.service
这是我的配置。
server {
listen 80;
root /home/user/projects/apple/public;
index index.php index.html index.htm;
server_name apple.dev;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
【解决方案3】:
我不确定有什么区别,但我删除了配置文件并复制了默认配置,对我需要的行进行了更改。 (即 server_name、root)
它开始工作了。