简体   繁体   English

NGINX 将图像请求传递给动态服务器

[英]NGINX pass image requests to dynamic server

NGINX in front of NodeJS server. NGINX 在 NodeJS 服务器前面。 NodeJS applications generate dynamic content (attached files such as png) and then call Twilio SMS API (MMS msg) which is provided a URL to the attachment. NodeJS 应用程序生成动态内容(附加文件,例如 png),然后调用 Twilio SMS API(MMS 消息),它提供了一个 URL 到附件。 How to pass these URL requests through to the NodeJS server as they are not static content in NGINX.如何将这些 URL 请求传递到 NodeJS 服务器,因为它们不是 NGINX 中的 static 内容。

Example: png image generated by NodeJS, and must be immediately accessible to Twilio API via URL that comes in through NGINX in front of NodeJS. Example: png image generated by NodeJS, and must be immediately accessible to Twilio API via URL that comes in through NGINX in front of NodeJS.

If nodejs generates URLs for PNG and these URLs are similar to each other at least part of the path, you can insert them in nginx location with regexp.如果 nodejs 为 PNG 生成 URL,并且这些 URL 至少在部分路径中彼此相似,则可以使用正则表达式将它们插入 nginx 位置。 But it should go before location, which handles regular PNGs.但它应该在处理常规 PNG 的位置之前为 go。

For example if your static pngs are in location例如,如果您的 static pngs 在位置

...

location ~ ^/.+\.(png|jpg|txt|css|js|ttf)$ {
  root /var/www/html;
}
...

and your nodejs generates pngs on path like "/twilio/abcabc/123.png".并且您的nodejs在“/twilio/abcabc/123.png”之类的路径上生成png。 Than you can insert this location before location with static:您可以在使用 static 的位置之前插入此位置:

...

location ~ ^/twilio/.+\.png$ {
  proxy_pass http://nodejs;
}

location ~ ^/.+\.(png|jpg|txt|css|js|ttf)$ {
  root /var/www/html;
}

...

In nginx documentation described order how request matchin location: "Then regular expressions are checked, in the order of their appearance in the configuration file."nginx 文档中描述了请求匹配位置的顺序:“然后按照它们在配置文件中出现的顺序检查正则表达式。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM