News for hackers. Stuff that matters.
Re:Using Nginx as an Object Storage Gateway by mnutt on Thursday December 02, 2021 @09:44PM (#29426059)
If you need random access to s3 within an ec2 region, sticking nginx in front of it as a caching proxy is unbelievably faster than hitting s3 directly; even moreso if you're multi-region.

I recently experimented with trying to have nginx rewrite images from png/jpeg to webp for clients that support it. I ended up with a solution where a lambda triggered off new files added to a bucket and re-encoded them as webp alongside the originals. When a request came into nginx, it would examine the URL and client Accept headers, and then first try to fetch the webp file from s3 before falling back to fetching the original from s3.

I was somewhat surprised that nginx was capable of doing it efficiently, given the nginx configuration format and all the moving pieces.

Re:Using Nginx as an Object Storage Gateway by gonzo41 on Thursday December 02, 2021 @09:51PM (#29426095)
If you;re doing this with an ec2, why not use CloudFront, and if you need a tiny bit of logic you could use API GW edge optimized and toss a lambda in there to do the logic bits.
Re:Using Nginx as an Object Storage Gateway by mnutt on Friday December 03, 2021 @12:14AM (#29426844)
That would work, too. It would be very expensive at scale and would be difficult to keep tail latencies down. Which might be ok for some cases, but wasn't for mine.
Re:Using Nginx as an Object Storage Gateway by halfmatthalfcat on Thursday December 02, 2021 @09:58PM (#29426138)
At Edge workers really are great at solving so many of these use cases.
Re:Using Nginx as an Object Storage Gateway by killingtime74 on Thursday December 02, 2021 @10:05PM (#29426172)
Nginx itself supports lua and JavaScript
Re:Using Nginx as an Object Storage Gateway by gonzo41 on Thursday December 02, 2021 @10:10PM (#29426208)
yeah but with an EC2 you're always running it. Going serverless you only pay when there's use.
Re:Using Nginx as an Object Storage Gateway by dikei on Thursday December 02, 2021 @10:19PM (#29426269)
Instead of re-encoding everything, have you considered using something like `imgproxy` to transcode image on demand and cached the result ?
Re:Using Nginx as an Object Storage Gateway by jgalt212 on Thursday December 02, 2021 @11:56PM (#29426769)
why webp over png/jpg? Is there that much of a difference to amortize the cost of the extra processing and/or caching?
Re:Using Nginx as an Object Storage Gateway by iostream23 on Friday December 03, 2021 @03:46AM (#29427951)
Só, nginx is a freemium webserver ($2500 IIRC, the open source community edition deliberately withheld features like hot reload of configs, not sure of current status wrt versions features parity etc.)

It can also serve as a proxy server, but we already have the finest proxy server in the world as open source: HAProxy

I urge anyone to learn it’s admittedly obscure but simple config file switches and be amazed at how many layers this software can operate on.

When you really need to performance tune your frontend in real-time, you will appreciate HAProxy and what it offers.

Re:Using Nginx as an Object Storage Gateway by bsagdiyev on Friday December 03, 2021 @06:18AM (#29428776)
After using HAProxy at work, I’ve been trying to slowly move my personal setups to using it. The config is a bit weird to learn, like nginx, at first but it really is performant.
Re:Using Nginx as an Object Storage Gateway by Datagenerator on Friday December 03, 2021 @07:03AM (#29429041)
Until you used Caddy?
Re:Using Nginx as an Object Storage Gateway by bsagdiyev on Friday December 03, 2021 @09:28AM (#29430365)
Absolutely not. We can pay HAProxy for support.
Re:Using Nginx as an Object Storage Gateway by sneak on Thursday December 02, 2021 @06:07PM (#29424166)
Note that this is part of the not-open-source nginx.
Re:Using Nginx as an Object Storage Gateway by tempay on Thursday December 02, 2021 @06:35PM (#29424531)
The article states:

> You can use both NGINX Open Source and NGINX Plus as the gateway to S3 or a compatible object store.

Re:Using Nginx as an Object Storage Gateway by mike_d on Thursday December 02, 2021 @06:44PM (#29424642)
Here be dragons. The free version of nginx will only do DNS resolution on a backend hostname at startup, the paid version will do periodic lookups.

They do mention this further down the page, but in 8 months when it randomly breaks you have to hope you remember it needs to be periodically restarted to keep working.

This is by far the stupidest paywalled feature ever, because it amount to downtime extortion.

Re:Using Nginx as an Object Storage Gateway by dmart on Thursday December 02, 2021 @06:52PM (#29424699)
There are hacky ways around it, though. The method here is something I've used: https://tenzer.dk/nginx-with-dynamic-upstreams/
Re:Using Nginx as an Object Storage Gateway by gary_0 on Thursday December 02, 2021 @07:46PM (#29425198)
Having to hack around the nginx paywall made me briefly consider going back to Apache.
Re:Using Nginx as an Object Storage Gateway by codetrotter on Thursday December 02, 2021 @08:13PM (#29425420)
Have you tried Caddy server? No affiliation just a happy user. It’s open source.

It may or may not be able to replace Nginx depending on your use case. For me Caddy has replaced everything I used to use Nginx for and more.

https://caddyserver.com/

Re:Using Nginx as an Object Storage Gateway by dmart on Thursday December 02, 2021 @08:47PM (#29425651)
I'm quite interested in Caddy. The last time I checked, things were in a rough spot with the v2 transition, but it looks like the documentation has improved.
Re:Using Nginx as an Object Storage Gateway by _hyn3 on Thursday December 02, 2021 @11:53PM (#29426753)
Apache Traffic Server (no relation to Apache itself) would be an excellent option: https://trafficserver.apache.org/
Re:Using Nginx as an Object Storage Gateway by fosk on Thursday December 02, 2021 @08:43PM (#29425623)
Kong Gateway - which is built on top of NGINX - provides frequent DNS lookups for free in the open source version, and we have implemented this feature a very long time ago (2017?) to overcome this limitation.

So if you need need this capability for free, check it out. Not only that, but SRV record resolutions too.

Re:Using Nginx as an Object Storage Gateway by tinus_hn on Thursday December 02, 2021 @07:07PM (#29424844)
It’s open source, what’s keeping you from patching out that limitation?
Re:Using Nginx as an Object Storage Gateway by jmg_ on Thursday December 02, 2021 @07:18PM (#29424949)
I've always been curious to see how project owners respond to someone re-implementing portions of paid features in an open source project.

Assuming the patch is valid, do they decline it citing the paid feature or do something like making a straw man argument against it?

Re:Using Nginx as an Object Storage Gateway by akerl_ on Thursday December 02, 2021 @07:26PM (#29425034)
I haven’t tried to pitch something to nginx, but as long as you did it as a clean implementation, “We’re declining to merge, since this is duplicative of code in our paid offering” is the general approach. And then you’re able to maintain your patch set alongside their upstream source.
Re:Using Nginx as an Object Storage Gateway by sneak on Friday December 03, 2021 @06:08AM (#29428702)
My patches removing spyware and phone-home in open source have been universally rejected.
Re:Using Nginx as an Object Storage Gateway by gary_0 on Thursday December 02, 2021 @07:41PM (#29425155)
Nothing. For instance, the Debian package nginx-extras includes implementations of some closed-source nginx features. But in my experience the patches are not particularly well-maintained (since they obviously won't be merged by nginx, there's already an official paid version, and the features are named differently from the closed-source ones so they're harder to find).
Re:Using Nginx as an Object Storage Gateway by mbreese on Thursday December 02, 2021 @09:09PM (#29425810)
Dumb question - do AWS S3 endpoints change DNS that much? Is the DNS resolution limit an issue with this specific workload, or just a general issue?
Re:Using Nginx as an Object Storage Gateway by ceejayoz on Thursday December 02, 2021 @09:21PM (#29425902)
Run `dig s3.amazonaws.com` a few times. It's got like a 5 second TTL and the IP changes every time.
Re:Using Nginx as an Object Storage Gateway by prpl on Friday December 03, 2021 @12:43AM (#29426991)
Use openresty local resolver with

set $proxy_url xxx; proxy_pass $proxy_url;

Re:Using Nginx as an Object Storage Gateway by iostream23 on Friday December 03, 2021 @03:49AM (#29427961)
Use HAProxy, this is what it is designed for.
Re:Using Nginx as an Object Storage Gateway by chespinoza on Thursday December 02, 2021 @06:41PM (#29424599)
Indeed, that makes me wonder how difficult for companies like Nginx is making profit from open source, well they were acquired by F5 a couple of years ago so probably they were doing quite well I think.
Re:Using Nginx as an Object Storage Gateway by rad_gruchalski on Thursday December 02, 2021 @09:38PM (#29426022)
And it’s S3 only. The title could mention that.
Re:Using Nginx as an Object Storage Gateway by chrislusf on Thursday December 02, 2021 @06:58PM (#29424770)
Interesting that SeaweedFS also has a similar named "Gateway to Remote Object Storage" https://github.com/chrislusf/seaweedfs/wiki/Gateway-to-Remot...

The difference is that SeaweedFS can support both read and write, with asynchronous write back. Nginx can support read only caching with 1 hour TTL

Re:Using Nginx as an Object Storage Gateway by dekobon on Thursday December 02, 2021 @07:10PM (#29424870)
Author of the article and project here...

SeaweedFS and this project have different purposes. This project is intended to show off how to configure NGINX to act as a S3 proxying gateway by using [njs](https://nginx.org/en/docs/njs/). If you look at the github for it, you will see it is just a collection of nginx config and javascript files. This all works will standard open source NGINX. All it does is proxy files like a L7 load balancer, but in this case, it adds AWS v2/v4 headers to the upstream requests.

As for caching, that is totally configurable to whatever you want; the example configuration is set to 1 hour but that is arbitrary. In fact, one of the interesting this is all of the additional functionality that can be enabled because the proxying is being done by NGINX.

Regarding read and write, that can be enabled for AWSv2 signatures, but it is more difficult to do in AWSv4 signatures. I have an idea about how to accomplish it with v4 signatures, but it will take some time to prototype it.

What is "asynchronous write back"?

Re:Using Nginx as an Object Storage Gateway by chrislusf on Thursday December 02, 2021 @11:35PM (#29426653)
SeaweedFS is very different from Nginx. It's just the names are so similar.

There are 2 ways to cache: write through and write back. You are using write through, which needs to write to the remote storage before returning. Write back is only writing to local copy, which is much faster to return. The actual updates are executed asynchronously.

Re:Using Nginx as an Object Storage Gateway by timuralp on Thursday December 02, 2021 @08:25PM (#29425503)
For requests with non-empty body with v4 signatures (e.g. PUT object) you can use Unsigned-Payload (https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-heade...) and not have to compute the payload sha256.
Re:Using Nginx as an Object Storage Gateway by conradfr on Friday December 03, 2021 @03:09AM (#29427736)
Coincidentally I wanted to do that for a side-project I launched yesterday [1]. I tried their nginx-s3-gateway image but couldn't get the authorization to AWS S3 to work.

I replaced it with Varnish with the files publicly available on the (cheaper) S3 compatible Scaleway. I guess a simple Nginx would have work the same at that point. My goal was mostly to minimize the bandwidth cost (which is not metered on my server).

[1] https://abx.funkybits.fr