2018-02-06 11:09:10 -05:00
# imageproxy
2020-06-23 18:52:41 -05:00
[![GoDoc ](https://img.shields.io/badge/godoc-reference-blue )](https://pkg.go.dev/willnorris.com/go/imageproxy)
2019-11-01 21:18:03 -05:00
[![Test Status ](https://github.com/willnorris/imageproxy/workflows/tests/badge.svg )](https://github.com/willnorris/imageproxy/actions?query=workflow%3Atests)
2020-06-21 12:50:32 -05:00
[![Test Coverage ](https://codecov.io/gh/willnorris/imageproxy/branch/main/graph/badge.svg )](https://codecov.io/gh/willnorris/imageproxy)
2019-06-09 20:00:19 -05:00
[![CII Best Practices ](https://bestpractices.coreinfrastructure.org/projects/2611/badge )](https://bestpractices.coreinfrastructure.org/projects/2611)
2013-11-27 11:42:33 -05:00
2023-08-02 10:30:38 -05:00
imageproxy is a caching image proxy server written in go. It features:
2015-05-21 11:07:38 -05:00
2023-08-02 10:30:38 -05:00
- basic image adjustments like resizing, cropping, and rotation
- access control using allowed hosts list or request signing (HMAC-SHA256)
- support for jpeg, png, webp (decode only), tiff, and gif image formats
(including animated gifs)
- caching in-memory, on disk, or with Amazon S3, Google Cloud Storage, Azure
Storage, or Redis
- easy deployment, since it's pure go
2015-05-17 23:43:55 -05:00
Personally, I use it primarily to dynamically resize images hosted on my own
2023-08-02 10:30:38 -05:00
site (read more in [this post][]). But you can also enable request signing and
2015-05-21 11:07:38 -05:00
use it as an SSL proxy for remote images, similar to [atmos/camo][] but with
additional image adjustment options.
2013-11-27 11:42:33 -05:00
2022-11-14 23:34:06 -05:00
I aim to keep imageproxy compatible with the two [most recent major go releases][].
2023-08-02 10:23:11 -05:00
I also keep track of the minimum go version that still works (currently go1.18), but that might change at any time.
2022-11-14 23:34:06 -05:00
You can see the go versions that are tested against in [.github/workflows/tests.yml][].
2021-02-11 17:09:13 -05:00
2015-05-17 23:43:55 -05:00
[this post]: https://willnorris.com/2014/01/a-self-hosted-alternative-to-jetpacks-photon-service
[atmos/camo]: https://github.com/atmos/camo
2021-02-11 17:09:13 -05:00
[most recent major go releases]: https://golang.org/doc/devel/release.html
[.github/workflows/tests.yml]: ./.github/workflows/tests.yml
2013-11-27 11:42:33 -05:00
2023-08-02 10:30:38 -05:00
## URL Structure
2013-11-27 11:42:33 -05:00
2013-12-26 14:14:28 -05:00
imageproxy URLs are of the form `http://localhost/{options}/{remote_url}` .
2013-11-27 11:42:33 -05:00
2023-08-02 10:30:38 -05:00
### Options
2013-11-27 11:42:33 -05:00
2017-08-31 02:27:35 -05:00
Options are available for cropping, resizing, rotation, flipping, and digital
2023-08-02 10:30:38 -05:00
signatures among a few others. Options for are specified as a comma delimited
list of parameters, which can be supplied in any order. Duplicate parameters
2017-08-31 02:27:35 -05:00
overwrite previous values.
2013-12-26 16:35:23 -05:00
2017-06-01 09:29:09 -05:00
See the full list of available options at
< https: / / godoc . org / willnorris . com / go / imageproxy # ParseOptions > .
2015-08-14 08:57:25 -05:00
2023-08-02 10:30:38 -05:00
### Remote URL
2013-11-27 11:42:33 -05:00
The URL of the original image to load is specified as the remainder of the
2023-08-02 10:30:38 -05:00
path, without any encoding. For example,
2013-11-27 11:42:33 -05:00
`http://localhost/200/https://willnorris.com/logo.jpg` .
In order to [optimize caching][], it is recommended that URLs not contain query
strings.
[optimize caching]: http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
2023-08-02 10:30:38 -05:00
### Examples
2013-12-06 20:01:13 -05:00
The following live examples demonstrate setting different options on [this
2013-12-06 20:40:35 -05:00
source image][small-things], which measures 1024 by 678 pixels.
2013-12-06 20:01:13 -05:00
2023-01-15 18:26:23 -05:00
[small-things]: https://willnorris.com/images/imageproxy/small-things.jpg
2013-12-06 20:01:13 -05:00
2023-08-02 10:30:38 -05:00
| Options | Meaning | Image |
| ---------------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 200x | 200px wide, proportional height | < a href = "https://willnorris.com/api/imageproxy/200x/https://willnorris.com/images/imageproxy/small-things.jpg" > < img src = "https://willnorris.com/api/imageproxy/200x/https://willnorris.com/images/imageproxy/small-things.jpg" alt = "200x" > < / a > |
| x0.15 | 15% original height, proportional width | < a href = "https://willnorris.com/api/imageproxy/x0.15/https://willnorris.com/images/imageproxy/small-things.jpg" > < img src = "https://willnorris.com/api/imageproxy/x0.15/https://willnorris.com/images/imageproxy/small-things.jpg" alt = "x0.15" > < / a > |
| 100x150 | 100 by 150 pixels, cropping as needed | < a href = "https://willnorris.com/api/imageproxy/100x150/https://willnorris.com/images/imageproxy/small-things.jpg" > < img src = "https://willnorris.com/api/imageproxy/100x150/https://willnorris.com/images/imageproxy/small-things.jpg" alt = "100x150" > < / a > |
| 100 | 100px square, cropping as needed | < a href = "https://willnorris.com/api/imageproxy/100/https://willnorris.com/images/imageproxy/small-things.jpg" > < img src = "https://willnorris.com/api/imageproxy/100/https://willnorris.com/images/imageproxy/small-things.jpg" alt = "100" > < / a > |
| 150,fit | scale to fit 150px square, no cropping | < a href = "https://willnorris.com/api/imageproxy/150,fit/https://willnorris.com/images/imageproxy/small-things.jpg" > < img src = "https://willnorris.com/api/imageproxy/150,fit/https://willnorris.com/images/imageproxy/small-things.jpg" alt = "150,fit" > < / a > |
| 100,r90 | 100px square, rotated 90 degrees | < a href = "https://willnorris.com/api/imageproxy/100,r90/https://willnorris.com/images/imageproxy/small-things.jpg" > < img src = "https://willnorris.com/api/imageproxy/100,r90/https://willnorris.com/images/imageproxy/small-things.jpg" alt = "100,r90" > < / a > |
| 100,fv,fh | 100px square, flipped horizontal and vertical | < a href = "https://willnorris.com/api/imageproxy/100,fv,fh/https://willnorris.com/images/imageproxy/small-things.jpg" > < img src = "https://willnorris.com/api/imageproxy/100,fv,fh/https://willnorris.com/images/imageproxy/small-things.jpg" alt = "100,fv,fh" > < / a > |
| 200x,q60 | 200px wide, proportional height, 60% quality | < a href = "https://willnorris.com/api/imageproxy/200x,q60/https://willnorris.com/images/imageproxy/small-things.jpg" > < img src = "https://willnorris.com/api/imageproxy/200x,q60/https://willnorris.com/images/imageproxy/small-things.jpg" alt = "200x,q60" > < / a > |
| 200x,png | 200px wide, converted to PNG format | < a href = "https://willnorris.com/api/imageproxy/200x,png/https://willnorris.com/images/imageproxy/small-things.jpg" > < img src = "https://willnorris.com/api/imageproxy/200x,png/https://willnorris.com/images/imageproxy/small-things.jpg" alt = "200x,png" > < / a > |
| cx175,cw400,ch300,100x | crop to 400x300px starting at (175,0), scale to 100px wide | < a href = "https://willnorris.com/api/imageproxy/cx175,cw400,ch300,100x/https://willnorris.com/images/imageproxy/small-things.jpg" > < img src = "https://willnorris.com/api/imageproxy/cx175,cw400,ch300,100x/https://willnorris.com/images/imageproxy/small-things.jpg" alt = "cx175,cw400,ch300,100x" > < / a > |
2013-12-06 20:01:13 -05:00
2019-03-16 20:05:12 -05:00
The [smart crop feature ](https://godoc.org/willnorris.com/go/imageproxy#hdr-Smart_Crop )
can best be seen by comparing crops of [this source image][judah-sheets], with
and without smart crop enabled.
2023-08-02 10:30:38 -05:00
| Options | Meaning | Image |
| ---------- | ------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 150x300 | 150x300px, standard crop | < a href = "https://willnorris.com/api/imageproxy/150x300/https://judahnorris.com/images/judah-sheets.jpg" > < img src = "https://willnorris.com/api/imageproxy/150x300/https://judahnorris.com/images/judah-sheets.jpg" alt = "200x400,sc" > < / a > |
| 150x300,sc | 150x300px, smart crop | < a href = "https://willnorris.com/api/imageproxy/150x300,sc/https://judahnorris.com/images/judah-sheets.jpg" > < img src = "https://willnorris.com/api/imageproxy/150x300,sc/https://judahnorris.com/images/judah-sheets.jpg" alt = "200x400" > < / a > |
2019-03-16 20:05:12 -05:00
[judah-sheets]: https://judahnorris.com/images/judah-sheets.jpg
2023-08-02 10:30:38 -05:00
Transformation also works on animated gifs. Here is [this source
2015-05-21 11:07:38 -05:00
image][material-animation] resized to 200px square and rotated 270 degrees:
2023-01-15 18:26:23 -05:00
[material-animation]: https://willnorris.com/images/imageproxy/material-animations.gif
2015-05-21 11:07:38 -05:00
2023-05-09 13:19:23 -05:00
< a href = "https://willnorris.com/api/imageproxy/200,r270/https://willnorris.com/images/imageproxy/material-animations.gif" > < img src = "https://willnorris.com/api/imageproxy/200,r270/https://willnorris.com/images/imageproxy/material-animations.gif" alt = "200,r270" > < / a >
2015-05-21 11:07:38 -05:00
2023-08-02 10:30:38 -05:00
## Getting Started
2014-11-21 12:42:42 -05:00
Install the package using:
2021-10-12 23:03:22 -05:00
go install willnorris.com/go/imageproxy/cmd/imageproxy@latest
2014-11-21 12:42:42 -05:00
2015-12-07 22:49:28 -05:00
Once installed, ensure `$GOPATH/bin` is in your `$PATH` , then run the proxy
using:
2014-11-21 12:42:42 -05:00
2015-02-15 01:39:14 -05:00
imageproxy
2014-11-21 12:42:42 -05:00
2018-09-15 00:49:33 -05:00
This will start the proxy on port 8080, without any caching and with no allowed
2023-08-02 10:30:38 -05:00
host list (meaning any remote URL can be proxied). Test this by navigating to
2014-11-21 12:42:42 -05:00
< http: / / localhost:8080 / 500 / https: / / octodex . github . com / images / codercat . jpg > and
you should see a 500px square coder octocat.
2023-08-02 10:30:38 -05:00
### Cache
2014-11-21 12:42:42 -05:00
2015-12-04 18:52:40 -05:00
By default, the imageproxy command does not cache responses, but caching can be
2023-08-02 10:30:38 -05:00
enabled using the `-cache` flag. It supports the following values:
- `memory` - uses an in-memory LRU cache. By default, this is limited to
100mb. To customize the size of the cache or the max age for cached items,
use the format `memory:size:age` where size is measured in mb and age is a
duration. For example, `memory:200:4h` will create a 200mb cache that will
cache items no longer than 4 hours.
- directory on local disk (e.g. `/tmp/imageproxy` ) - will cache images
on disk
- s3 URL (e.g. `s3://region/bucket-name/optional-path-prefix` ) - will cache
images on Amazon S3. This requires either an IAM role and instance profile
with access to your your bucket or `AWS_ACCESS_KEY_ID` and `AWS_SECRET_KEY`
environmental variables be set. (Additional methods of loading credentials
are documented in the [aws-sdk-go session
package](https://docs.aws.amazon.com/sdk-for-go/api/aws/session/)).
Additional configuration options ([further documented here][aws-options])
may be specified as URL query string parameters, which are mostly useful
when working with s3-compatible services:
- "endpoint" - specify an alternate API endpoint
- "disableSSL" - set to "1" to disable SSL when calling the API
- "s3ForcePathStyle" - set to "1" to force the request to use path-style addressing
For example, when working with [minio ](https://minio.io ), which doesn't use
regions, provide a dummy region value and custom endpoint value:
s3://fake-region/bucket/folder?endpoint=minio:9000& disableSSL=1& s3ForcePathStyle=1
Similarly, for [Digital Ocean Spaces ](https://www.digitalocean.com/products/spaces/ ),
provide a dummy region value and the appropriate endpoint for your space:
s3://fake-region/bucket/folder?endpoint=sfo2.digitaloceanspaces.com
[aws-options]: https://docs.aws.amazon.com/sdk-for-go/api/aws/#Config
- gcs URL (e.g. `gcs://bucket-name/optional-path-prefix` ) - will cache images
on Google Cloud Storage. Authentication is documented in Google's
[Application Default Credentials
docs](https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application).
- azure URL (e.g. `azure://container-name/` ) - will cache images on
Azure Storage. This requires `AZURESTORAGE_ACCOUNT_NAME` and
`AZURESTORAGE_ACCESS_KEY` environment variables to bet set.
- redis URL (e.g. `redis://hostname/` ) - will cache images on
the specified redis host. The full URL syntax is defined by the [redis URI
registration](https://www.iana.org/assignments/uri-schemes/prov/redis).
Rather than specify password in the URI, use the `REDIS_PASSWORD`
environment variable.
2015-12-04 18:52:40 -05:00
2015-12-07 23:56:56 -05:00
For example, to cache files on disk in the `/tmp/imageproxy` directory:
2015-12-04 18:52:40 -05:00
2015-12-07 23:56:56 -05:00
imageproxy -cache /tmp/imageproxy
2014-11-21 12:42:42 -05:00
2015-05-12 00:46:00 -05:00
Reload the [codercat URL][], and then inspect the contents of
2023-08-02 10:30:38 -05:00
`/tmp/imageproxy` . Within the subdirectories, there should be two files, one
2015-12-07 23:56:56 -05:00
for the original full-size codercat image, and one for the resized 500px
version.
2015-05-12 00:46:00 -05:00
[codercat URL]: http://localhost:8080/500/https://octodex.github.com/images/codercat.jpg
2014-11-21 12:42:42 -05:00
2019-06-09 17:09:55 -05:00
Multiple caches can be specified by separating them by spaces or by repeating
2023-08-02 10:30:38 -05:00
the `-cache` flag multiple times. The caches will be created in a [tiered
2019-06-09 17:09:55 -05:00
fashion][]. Typically this is used to put a smaller and faster in-memory cache
2023-08-02 10:30:38 -05:00
in front of a larger but slower on-disk cache. For example, the following will
2019-06-09 17:09:55 -05:00
first check an in-memory cache for an image, followed by a gcs bucket:
2017-09-17 04:55:41 -05:00
imageproxy -cache memory -cache gcs://my-bucket/
[tiered fashion]: https://godoc.org/github.com/die-net/lrucache/twotier
2023-08-02 10:30:38 -05:00
### Allowed Referrer List
2015-06-14 03:26:40 -05:00
2015-12-07 22:49:28 -05:00
You can limit images to only be accessible for certain hosts in the HTTP
referrer header, which can help prevent others from hotlinking to images. It can
2015-12-07 23:56:56 -05:00
be enabled by running:
2015-06-14 03:26:40 -05:00
imageproxy -referrers example.com
2023-08-02 10:30:38 -05:00
Reload the [codercat URL][], and you should now get an error message. You can
2015-06-14 03:26:40 -05:00
specify multiple hosts as a comma separated list, or prefix a host value with
`*.` to allow all sub-domains as well.
2023-08-02 10:30:38 -05:00
### Allowed and Denied Hosts List
2014-11-21 12:42:42 -05:00
You can limit the remote hosts that the proxy will fetch images from using the
2023-08-02 10:30:38 -05:00
`allowHosts` and `denyHosts` flags. This is useful, for example, for locking
the proxy down to your own hosts to prevent others from abusing it. Of course
2017-03-23 04:42:39 -05:00
if you want to support fetching from any host, leave off these flags.
Try it out by running:
2014-11-21 12:42:42 -05:00
2019-03-21 19:13:49 -05:00
imageproxy -allowHosts example.com
2014-11-21 12:42:42 -05:00
2017-03-23 04:42:39 -05:00
Reload the [codercat URL][], and you should now get an error message.
Alternately, try running:
imageproxy -denyHosts octodex.github.com
Reloading the [codercat URL][] will still return an error message.
You can specify multiple hosts as a comma separated list to either flag, or
2020-06-19 19:30:49 -05:00
prefix a host value with `*.` to allow or deny all sub-domains. You can
also specify a netblock in CIDR notation (`127.0.0.0/8`) -- this is useful for
blocking reserved ranges like `127.0.0.0/8` , `192.168.0.0/16` , etc.
2017-03-23 04:42:39 -05:00
2020-06-19 19:30:49 -05:00
If a host matches both an allowed and denied host, the request will be denied.
2015-05-12 00:46:00 -05:00
2023-08-02 10:30:38 -05:00
### Allowed Content-Type List
2018-09-14 23:29:05 -05:00
You can limit what content types can be proxied by using the `contentTypes`
flag. By default, this is set to `image/*` , meaning that imageproxy will
process any image types. You can specify multiple content types as a comma
separated list, and suffix values with `*` to perform a wildcard match. Set the
flag to an empty string to proxy all requests, regardless of content type.
2023-08-02 10:30:38 -05:00
### Signed Requests
2015-05-12 00:46:00 -05:00
2023-08-02 10:30:38 -05:00
Instead of an allowed host list, you can require that requests be signed. This
2018-09-15 00:49:33 -05:00
is useful in preventing abuse when you don't have just a static list of hosts
2023-08-02 10:30:38 -05:00
you want to allow. Signatures are generated using HMAC-SHA256 against the
2018-09-15 00:49:33 -05:00
remote URL, and url-safe base64 encoding the result:
2015-05-12 00:46:00 -05:00
base64urlencode(hmac.New(sha256, < key > ).digest(< remote_url > ))
2023-08-02 10:30:38 -05:00
The HMAC key is specified using the `signatureKey` flag. If this flag
2015-05-12 00:46:00 -05:00
begins with an "@", the remainder of the value is interpreted as a file on disk
which contains the HMAC key.
Try it out by running:
2020-02-02 13:45:39 -05:00
imageproxy -signatureKey "secretkey"
2015-05-12 00:46:00 -05:00
2023-08-02 10:30:38 -05:00
Reload the [codercat URL][], and you should see an error message. Now load a
2019-03-16 22:09:05 -05:00
[signed codercat URL][] (which contains the [signature option][]) and verify
that it loads properly.
2015-05-12 00:46:00 -05:00
[signed codercat URL]: http://localhost:8080/500,sXyMwWKIC5JPCtlYOQ2f4yMBTqpjtUsfI67Sp7huXIYY=/https://octodex.github.com/images/codercat.jpg
2019-03-16 22:09:05 -05:00
[signature option]: https://godoc.org/willnorris.com/go/imageproxy#hdr-Signature
2015-05-12 00:46:00 -05:00
Some simple code samples for generating signatures in various languages can be
2023-08-02 10:30:38 -05:00
found in [docs/url-signing.md ](/docs/url-signing.md ). Multiple valid signature
2020-02-02 13:45:39 -05:00
keys may be provided to support key rotation by repeating the `signatureKey`
2023-08-02 10:30:38 -05:00
flag multiple times, or by providing a space-separated list of keys. To use a
2020-02-02 13:45:39 -05:00
key with a literal space character, load the key from a file using the "@"
prefix documented above.
2015-05-12 00:46:00 -05:00
If both a whiltelist and signatureKey are specified, requests can match either.
2018-09-15 00:49:33 -05:00
In other words, requests that match one of the allowed hosts don't necessarily
need to be signed, though they can be.
2015-05-12 00:46:00 -05:00
2023-08-02 10:30:38 -05:00
### Default Base URL
2015-02-20 00:34:22 -05:00
Typically, remote images to be proxied are specified as absolute URLs.
However, if you commonly proxy images from a single source, you can provide a
2023-08-02 10:30:38 -05:00
base URL and then specify remote images relative to that base. Try it out by
2015-12-07 22:49:28 -05:00
running:
2015-02-20 00:34:22 -05:00
imageproxy -baseURL https://octodex.github.com/
Then load the codercat image, specified as a URL relative to that base:
2023-08-02 10:30:38 -05:00
< http: / / localhost:8080 / 500 / images / codercat . jpg > . Note that this is not an
2015-02-20 00:34:22 -05:00
effective method to mask the true source of the images being proxied; it is
2023-08-02 10:30:38 -05:00
trivial to discover the base URL being used. Even when a base URL is
2015-02-20 00:34:22 -05:00
specified, you can always provide the absolute URL of the image to be proxied.
2023-08-02 10:30:38 -05:00
### Scaling beyond original size
2015-08-12 13:45:19 -05:00
2015-12-07 22:49:28 -05:00
By default, the imageproxy won't scale images beyond their original size.
However, you can use the `scaleUp` command-line flag to allow this to happen:
2015-08-12 13:45:19 -05:00
imageproxy -scaleUp true
2014-11-21 12:42:42 -05:00
2023-08-02 10:30:38 -05:00
### WebP and TIFF support
2017-06-01 10:10:34 -05:00
Imageproxy can proxy remote webp images, but they will be served in either jpeg
2017-08-31 02:24:59 -05:00
or png format (this is because the golang webp library only supports webp
2023-08-02 10:30:38 -05:00
decoding) if any transformation is requested. If no format is specified,
imageproxy will use jpeg by default. If no transformation is requested (for
2017-08-31 02:24:59 -05:00
example, if you are just using imageproxy as an SSL proxy) then the original
webp image will be served as-is without any format conversion.
2017-08-31 19:03:17 -05:00
Because so few browsers support tiff images, they will be converted to jpeg by
default if any transformation is requested. To force encoding as tiff, pass the
"tiff" option. Like webp, tiff images will be served as-is without any format
conversion if no transformation is requested.
2023-08-02 10:30:38 -05:00
Run `imageproxy -help` for a complete list of flags the command accepts. If
2017-08-31 02:24:59 -05:00
you want to use a different caching implementation, it's probably easiest to
just make a copy of `cmd/imageproxy/main.go` and customize it to fit your
needs... it's a very simple command.
2017-06-01 10:10:34 -05:00
2023-08-02 10:30:38 -05:00
### Environment Variables
2019-06-09 16:02:21 -05:00
All configuration flags have equivalent environment variables of the form
2023-08-02 10:30:38 -05:00
`IMAGEPROXY_$NAME` . For example, an on-disk cache could be configured by calling
2019-06-09 16:02:21 -05:00
IMAGEPROXY_CACHE="/tmp/imageproxy" imageproxy
2023-08-02 10:30:38 -05:00
## Deploying
2014-11-21 12:42:42 -05:00
2017-09-09 03:14:20 -05:00
In most cases, you can follow the normal procedure for building a deploying any
2023-08-02 10:30:38 -05:00
go application. For example:
2017-09-09 03:14:20 -05:00
2023-08-02 10:30:38 -05:00
- `go build willnorris.com/go/imageproxy/cmd/imageproxy`
- copy resulting binary to `/usr/local/bin`
- copy [`etc/imageproxy.service` ](etc/imageproxy.service ) to
`/lib/systemd/system` and enable using `systemctl` .
2017-09-09 03:14:20 -05:00
Instructions have been contributed below for running on other platforms, but I
don't have much experience with them personally.
2014-11-21 12:42:42 -05:00
2023-08-02 10:30:38 -05:00
### Heroku
2015-08-13 11:47:33 -05:00
2015-12-07 22:49:28 -05:00
It's easy to vendorize the dependencies with `Godep` and deploy to Heroku. Take
2021-01-22 10:08:00 -05:00
a look at [this GitHub repo ](https://github.com/oreillymedia/prototype-imageproxy/tree/heroku )
(make sure you use the `heroku` branch).
2023-08-02 10:30:38 -05:00
### AWS Elastic Beanstalk
2021-01-22 10:08:00 -05:00
[O’ Reilly Media ](https://github.com/oreillymedia ) set up [a repository ](https://github.com/oreillymedia/prototype-imageproxy )
with everything you need to deploy imageproxy to Elastic Beanstalk. Just follow the instructions
in the [README ](https://github.com/oreillymedia/prototype-imageproxy/blob/master/Readme.md ).
2015-08-13 11:47:33 -05:00
2023-08-02 10:30:38 -05:00
### Docker
2015-05-29 04:49:24 -05:00
2021-10-12 23:03:22 -05:00
A docker image is available at [`ghcr.io/willnorris/imageproxy` ](https://github.com/willnorris/imageproxy/pkgs/container/imageproxy ).
2015-05-29 04:49:24 -05:00
You can run it by
2023-08-02 10:30:38 -05:00
2015-05-29 04:49:24 -05:00
```
2021-10-12 23:03:22 -05:00
docker run -p 8080:8080 ghcr.io/willnorris/imageproxy -addr 0.0.0.0:8080
2015-05-29 04:49:24 -05:00
```
2014-11-21 12:42:42 -05:00
2016-05-01 00:55:03 -05:00
Or in your Dockerfile:
```
2019-06-12 11:19:01 -05:00
ENTRYPOINT ["/app/imageproxy", "-addr 0.0.0.0:8080"]
2016-05-01 00:55:03 -05:00
```
2019-09-13 07:39:48 -05:00
If running imageproxy inside docker with a bind-mounted on-disk cache, make sure
the container is running as a user that has write permission to the mounted host
2023-08-02 10:30:38 -05:00
directory. See more details in
2019-09-13 07:39:48 -05:00
[#198 ](https://github.com/willnorris/imageproxy/issues/198 ).
2021-10-13 10:44:00 -05:00
Note that all configuration options can be set using [environment
variables](#environment-variables), which is often the preferred approach for
containers.
2023-08-02 10:30:38 -05:00
### nginx
2016-05-01 00:55:03 -05:00
2019-05-12 13:09:26 -05:00
Use the `proxy_pass` directive to send requests to your imageproxy instance.
For example, to run imageproxy at the path "/api/imageproxy/", set:
2016-05-01 00:55:03 -05:00
```
2019-05-12 13:09:26 -05:00
location /api/imageproxy/ {
proxy_pass http://localhost:4593/;
}
```
Depending on other directives you may have in your nginx config, you might need
to alter the precedence order by setting:
```
location ^~ /api/imageproxy/ {
proxy_pass http://localhost:4593/;
2016-05-01 00:55:03 -05:00
}
```
2023-08-02 10:30:38 -05:00
## Clients
2023-02-18 12:34:25 -05:00
- [Ruby ](https://github.com/azolf/imageproxy_ruby )
2023-08-02 10:30:38 -05:00
## License
2013-11-27 11:42:33 -05:00
2021-03-10 15:24:13 -05:00
imageproxy is copyright its respective authors. All of my personal work on
imageproxy through 2020 (which accounts for the majority of the code) is
2023-08-02 10:30:38 -05:00
copyright Google, my employer at the time. It is available under the [Apache
2021-03-10 15:24:13 -05:00
2.0 License](./LICENSE).