laravel - nginx 上的 Laravel 对除索引以外的所有路由都表示 404
问题描述
我已经使用 nginx、php 7.4 fpm 和 mysql 8 在 Docker 上设置了 Laravel。我是 Docker 新手,我一直在学习几个教程,并且设法在一个单独的容器中运行每个服务,并在不同的目录中运行代码。
只有索引页面有效,但没有任何其他路线。
码头工人-compose.yml
version: '3'
services:
nginx:
build:
context: ./nginx
volumes:
- ../laravelproject:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/sites/:/etc/nginx/sites-available
- ./nginx/conf.d/:/etc/nginx/conf.d
depends_on:
- php-fpm
ports:
- "80:80"
- "443:443"
php-fpm:
build:
context: ./php-fpm
volumes:
- ../laravelproject:/var/www
- ../laravelproject/serve_config/custom.ini:/usr/local/etc/php/conf.d/custom.ini
database:
build:
context: ./database
environment:
- MYSQL_DATABASE=mydb
- MYSQL_USER=myuser
- MYSQL_PASSWORD=secret
- MYSQL_ROOT_PASSWORD=docker
volumes:
- ./database/data.sql:/docker-entrypoint-initdb.d/data.sql
command: ['--default-authentication-plugin=mysql_native_password']
站点文件夹中的默认配置
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name localhost;
root /var/www;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
log_not_found off;
}
}
conf.d 文件夹中的默认配置
upstream php-upstream {
server php-fpm:9000;
}
索引页面工作得很好,但是当我添加一个新路由时,它显示来自 nginx 的 404。我对 docker 没有太多经验,我一直在遵循几个教程来设置它。
谢谢
解决方案
我找到了解决办法。我改变了根,它工作。
root /var/www/public
推荐阅读
- winforms - WebView2 不能在缩放的监视器上缩放
- c# - 西装外套 | MDE | 在应用程序中随时获取功能键的值
- python - Leetcode 编译器在为具有多个方法的类执行输入时如何工作?
- windows - PowerShell 多条语句单行搞乱了标准输出顺序
- php - 如何使用 PHP 从服务器上的保管箱保存文件
- java - 如何声明一个接受任何类型 Function<> 的方法引用的变量
- etl - PENTAHO SPOON - 将单个表格输入拆分为多个 excel 输出
- regex - Bash sed 查找最后一个单词包含字母的行
- sql - 触发器之前的 Mariadb 未更新某些列
- vb.net - 设置访问报告的数据源