我使用 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/