首页 > 解决方案 > Nginx 配置以在根文件夹中提供动态文件

问题描述

我有一个具有以下结构的 mern 堆栈应用程序

.app/
  --client folder
-server.js
-storage folder

该应用程序在本地运行良好,但当我部署到 amazone (ec2) 并配置 pm2 和 nginx 时,一切正常,但保存在我的存储文件夹中的图像的唯一问题似乎没有提供。构建文件夹中的静态图像正常显示,但是当用户上传他的个人资料图像时,例如保存在存储中的图像,图像被保存但不显示。

我的 nginx 配置很常见:

root /path/tp/build;

location / {
   try_files $uri /index.html;
}

location /api/ {
  proxy_pass http://localhost:8080;
 //other default configs;
}

我试图使用 config 使其工作,但没有成功。我还在 nginx 配置中为存储文件夹添加了一个位置

location /storage/ {
   root /path/to/storage/;
   try_files $uri /;
}

我会很感激任何帮助,谢谢。

标签: node.jsnginxamazon-ec2

解决方案


推荐阅读