php - Laravel、Docker 和 Nginx : 404 for all files in/public folder

标签 php laravel docker nginx

我使用 docker-compose 3.3 和 Nginx 1.17 在 Laravel 7 中创建了一个新项目。

在 Laravel 上创建的点运行良好,当我尝试访问“/public”文件夹中的任何静态 Assets 时出现问题。我尝试使用 .css.js 文件以及 robots.txt 但 Laravel 返回 404 not found 错误。

这是我的nginx.conf(取自https://laravel.com/docs/7.x/deployment#nginx)

events {
}

http {
    server {
        server {
        listen 80;
        server_name localhost;
        root /var/www/app/public;

        index index.html index.htm index.php;

        charset utf-8;

        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }

        error_page 404 /index.php;

        location ~ \.php$ {
            fastcgi_pass app:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            include fastcgi_params;
        }

        location ~ /\.(?!well-known).* {
            deny all;
        }
    }
}

我尝试了在论坛和 Stackoverflow 上找到的不同修复方法,例如重新编译文件、清除缓存...但没有任何效果。

你能发现问题吗?

最佳答案

你能试试下面的配置吗:

server {
    listen 80;
    index index.php index.html;
    server_name localhost;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html/public;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

关于php - Laravel、Docker 和 Nginx : 404 for all files in/public folder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61708117/

相关文章:

mongodb - Symfony 返回 "MongoId Class not found"错误

javascript - 更新使用 ajax 动态添加的行

php - 如何让 CodeIgniter 创建新文件夹?

php - 如果数据库中没有值我收到错误

javascript - jQuery ajaxForm 完整版有时有效,有时它只触发 native JavaScript 函数然后停止

php - Laravel Horizo​​n 长时间等待检测设置 - 无法延长等待时间

laravel 与 vagrant 和 virtualbox - 版本 10 安装但 11 时 "vagrant up"

php - 为什么发生occuer语法错误,意外的 ';',期望的 ')'(查看:/var/www/resources/views/home.blade.php) [duplicate]

amazon-web-services - ECS 容器无法访问数据库

postgresql - Docker容器的可靠性