nginx 和 nodejs 从动态文件夹中提供图像 [英] nginx and nodejs serve images from dynamic folder
本文介绍了nginx 和 nodejs 从动态文件夹中提供图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个 nginx 设置:
Hi i have this nginx setup:
server {
listen 80;
server_name xxxxxx.xx www.xxxxxxx.xx;
root /home/xxxx/public_html;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
#proxy_redirect off;
#proxy_cache_bypass $http_upgrade;
}
}
我的应用程序在上传/用户中创建文件夹,然后是用户的 ID,然后将图像存储到其中.每个用户在uploads/user/xxxx 中都有自己的文件夹.
My app creates folders inside the uploads/user followed by the user's ID and then stores images into it. Every user have his own folder inside uploads/user/xxxx.
例如
/uploads/user/5878db663e67e3535a47c638/1085.github-logo.png
该应用在浏览器中运行良好,但当用户上传图像时,它无法显示,因此 404 上升.
The app works fine in browser but when the user uploads the image it cannot be displayed so a 404 rises.
我能做什么?
推荐答案
您可以使用 try_files
来提供静态内容(如果存在),否则请遵循 NodeJS:
You can use try_files
to serve up static content (if it exists) and otherwise defer to NodeJS:
root /home/xxxx/public_html;
location / {
try_files $uri $uri/ @proxy;
}
location @proxy {
proxy_pass http://127.0.0.1:3000;
...
}
有关详细信息,请参阅本文档.
See this document for details.
这篇关于nginx 和 nodejs 从动态文件夹中提供图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文