我正在开发一个项目与Reactjs和Laravel(微风版本)。
该项目是dockerized和服务,我使用Nginx作为web服务。我将它配置为通过在前端url的末尾添加/api来访问laravel后端。
一切都很好,但当我试图访问上传的图像文件在公共文件夹(后端),我有404错误。
这是我的nginx配置文件:
.
.
.
# laravel backend
location ~ /api {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
root /var/www/html/backend/public;
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass laravel:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_hide_header X-Powered-By;
}
.
.
.
.
我有另一个根在我的nginx配置文件为我的前端:
server {
listen 80 default_server;
server_name _;
server_tokens off;
root /var/www/html/frontend;
.
.
.
在Nginx配置文件中添加我的上传文件夹(在laravel公共文件夹内)的新位置后,问题得到了解决:
location /uploads/ {
alias /var/www/html/backend/public/uploads/;
}