{"id":13400283,"url":"https://github.com/shinsenter/docker-imgproxy","last_synced_at":"2026-01-31T13:49:17.701Z","repository":{"id":40438112,"uuid":"415267715","full_name":"shinsenter/docker-imgproxy","owner":"shinsenter","description":"🌐 An ultra fast, production-grade on-the-fly image processing web server. Designed for high throughput with Nginx caching. Powered by imgproxy.","archived":false,"fork":false,"pushed_at":"2024-08-01T02:21:36.000Z","size":1269,"stargazers_count":192,"open_issues_count":0,"forks_count":34,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-01T20:02:01.437Z","etag":null,"topics":["docker-compose","http2","image-compression","image-optimization","image-proxy","image-resizing","image-server","imgproxy","instant-images","nginx","on-the-fly-image-processing","on-the-fly-resize","proxy-server","thumbnail-generator","thumbnailer"],"latest_commit_sha":null,"homepage":"https://shinsenter.github.io/docker-imgproxy/","language":"Dockerfile","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinsenter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"shinsenter","custom":["https://www.paypal.me/shinsenter"]}},"created_at":"2021-10-09T09:49:48.000Z","updated_at":"2024-08-01T02:21:40.000Z","dependencies_parsed_at":"2024-01-16T09:57:25.643Z","dependency_job_id":"585cb074-4fa8-42a0-a705-902189d268ae","html_url":"https://github.com/shinsenter/docker-imgproxy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinsenter%2Fdocker-imgproxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinsenter%2Fdocker-imgproxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinsenter%2Fdocker-imgproxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinsenter%2Fdocker-imgproxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinsenter","download_url":"https://codeload.github.com/shinsenter/docker-imgproxy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221440178,"owners_count":16821599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker-compose","http2","image-compression","image-optimization","image-proxy","image-resizing","image-server","imgproxy","instant-images","nginx","on-the-fly-image-processing","on-the-fly-resize","proxy-server","thumbnail-generator","thumbnailer"],"created_at":"2024-07-30T19:00:50.243Z","updated_at":"2026-01-31T13:49:17.648Z","avatar_url":"https://github.com/shinsenter.png","language":"Dockerfile","readme":"# Ultra Image Server\n\n![www/noimage_thumb.jpg](www/noimage_thumb.jpg)\n\n🌐 A production grade on-the-fly image processing server setup using [imgproxy](https://imgproxy.net) and [Nginx caching](https://www.Nginx.com/products/Nginx/caching/).\n\n## Table of contents\n- [Why it's good](#why-its-good)\n- [Getting started](#getting-started)\n- [Examples](#examples)\n- [Debugging](#debugging)\n- [Configurations](#configurations)\n\n---\n\n![docker-imgproxy](www/project.jpg)\n\n- **Author**: Mai Nhut Tan \u003cshin@shin.company\u003e\n- **Copyright**: 2021-2024 SHIN Company \u003chttps://code.shin.company/docker-imgproxy#readme\u003e\n\n\n## Disclaimer\n\nThis project provides a solid foundation for building a custom image processing server. While it's designed for general use, you might need to tweak it further to perfectly match your specific needs.\n\nI poured my heart into this project, hoping it serves as a valuable learning resource for anyone interested in exploring image processing configurations. If it doesn't fully address your current requirements, don't hesitate to keep searching for the perfect solution!\n\n\n## Support my activities\n\nIf you find this project useful, consider donating via [PayPal](https://www.paypal.me/shinsenter) or open an issue on [Github](https://github.com/shinsenter/docker-imgproxy/discussions/new/choose). Your support helps keep this project maintained and improved for the community.\n\n\n---\n\n\n## Why it's good\n\nExperience the ultimate in efficient image delivery with our cutting-edge solution:\n\n- Lightning-fast on-the-fly thumbnail generation powered by [`imgproxy`](https://imgproxy.net).\n- High availability and unparalleled performance thanks to Nginx content caching.\n- Bid farewell to [URL signature](https://docs.imgproxy.net/usage/signing_url#configuring-url-signature) management hassles while maintaining top-notch security.\n- Effortless serving of local files or remote server content.\n- SEO-friendly URL crafting without exposing [complex `imgproxy` options](https://docs.imgproxy.net/usage/processing).\n- Unmatched flexibility:\n  - Customize image presets for any request.\n  - Dynamic origin server selection.\n  - Graceful fallback image handling for unavailable sources.\n- Hassle-free SSL configuration with built-in HTTP/2 support for blazing-fast load times.\n- Intelligent image format conversion to WebP (or AVIF) for browser compatibility.\n- Seamless visual experience across devices.\n\nUnleash the power of our cutting-edge solution and take your project to new heights with efficient image delivery.\n\n---\n\n\n## Getting started\n\n### Pull this project from Github\n\nPlease run the below command to download the project to your local machine:\n\n```shell\ngit clone https://github.com/shinsenter/docker-imgproxy.git docker-imgproxy\n```\n\nOr:\n\n```shell\ncurl -skL https://github.com/shinsenter/docker-imgproxy/archive/refs/heads/main.zip -o docker-imgproxy.zip \u0026\u0026 unzip docker-imgproxy.zip\nrm -f docker-imgproxy.zip\nmv docker-imgproxy-main docker-imgproxy\n```\n\n### Prepare your files\n\nChange your working directory to downloaded directory in the above step.\n\n```shell\ncd docker-imgproxy\n```\n\nThen put your image files to be served to the folder `www/`.\n\nThere are some sample files available (a sample image `cacti.jpg`, a watermark, and some fallback images).\n\n\n### Start the server\n\n```shell\ncd docker-imgproxy\ndocker-compose up -d --build --remove-orphans --force-recreate\n```\n\nThat's all! 😉\n\n\u003csmall\u003eNote: This setup requires [Docker Compose](https://docs.docker.com/compose/) installed. If you have already installed Docker Desktop or Docker Toolbox, then no need of installation for Docker Compose.\u003c/small\u003e\n\nIf you like this setup, please [support my works](#support-my-activities) 😉.\n\n---\n\n\n## Examples\n\n### Local images\n\nAssuming that we want to generate various thumbnail images from the original file named `cacti.jpg`.\n\nI already created some preset names, such as `_thumb` or `_w200`, and I add preset names to the original URL to get thumbnails from it.\n\n\u003e Image with no preset (it is resized to max-width=1600 as default).\u003cbr/\u003e\n\u003e http://localhost/cacti.jpg\n\n\n\u003e The image with preset `_w200` applied (`200` is a dynamic number).\u003cbr/\u003e\n\u003e http://localhost/_w200/cacti.jpg\n\n\n\u003e The image with preset `_blurry` applied.\u003cbr/\u003e\n\u003e http://localhost/_blurry/cacti.jpg\n\n\n\u003e The image with preset `_small` applied.\u003cbr/\u003e\n\u003e http://localhost/_small/cacti.jpg\n\n\n\u003e The image with preset `_medium` applied.\u003cbr/\u003e\n\u003e http://localhost/_medium/cacti.jpg\n\n\n\u003e The image with preset `_thumb` applied.\u003cbr/\u003e\n\u003e http://localhost/_thumb/cacti.jpg\n\n\n\u003e The image with preset `_square` applied.\u003cbr/\u003e\n\u003e http://localhost/_square/cacti.jpg\n\n\n\u003e The image with preset `_masked` applied.\u003cbr/\u003e\n\u003e http://localhost/_masked/cacti.jpg\n\n\n\u003e Or just to download the image (with filters applied).\u003cbr/\u003e\n\u003e http://localhost/_download/cacti.jpg\n\n\nSee [my configurations](#advanced-settings) to know how it works.\n\n\n### Remote images\n\nWith the same presets as above examples, we are going to serve an image [by NASA](https://mars.nasa.gov/system/downloadable_items/40368_PIA22228.jpg) using the alias `@nasa`, that will be added in these URLs.\n\n\u003csmall\u003eNote: the image source is from NASA, it may be unavailable in the future.\u003c/small\u003e\n\n\u003e Image with no preset (it is resized to max-width=1600 as default).\u003cbr/\u003e\n\u003e http://localhost/@nasa/40368_PIA22228.jpg\n\n\n\u003e The image with preset `_w200` applied (`200` is a dynamic number).\u003cbr/\u003e\n\u003e http://localhost/@nasa/_w200/40368_PIA22228.jpg\n\n\n\u003e The image with preset `_blurry` applied.\u003cbr/\u003e\n\u003e http://localhost/@nasa/_blurry/40368_PIA22228.jpg\n\n\n\u003e The image with preset `_small` applied.\u003cbr/\u003e\n\u003e http://localhost/@nasa/_small/40368_PIA22228.jpg\n\n\n\u003e The image with preset `_medium` applied.\u003cbr/\u003e\n\u003e http://localhost/@nasa/_medium/40368_PIA22228.jpg\n\n\n\u003e The image with preset `_thumb` applied.\u003cbr/\u003e\n\u003e http://localhost/@nasa/_thumb/40368_PIA22228.jpg\n\n\n\u003e The image with preset `_square` applied.\u003cbr/\u003e\n\u003e http://localhost/@nasa/_square/40368_PIA22228.jpg\n\n\n\u003e The image with preset `_masked` applied.\u003cbr/\u003e\n\u003e http://localhost/@nasa/_masked/40368_PIA22228.jpg\n\n\n\u003e Or just to download the image (with filters applied).\u003cbr/\u003e\n\u003e http://localhost/@nasa/_download/40368_PIA22228.jpg\n\n\n#### Supported origin servers\n\nThis setup serve images from other public origin servers, as well as from Amazon S3 buckets, Google Cloud and Azure Blob.\n\nYou can learn how to serve files from private storage in the [configurations section](#serving-files-from-private-storage).\n\n\n#### Base64 encoded URLs\n\nThe source URL can be encrypted with URL-safe Base64, prepended by the `/@base64/` prefix. So you can access the remote images like the below:\n\n\u003csmall\u003eNote: the image source is from NASA, it may be unavailable in the future.\u003c/small\u003e\n\n\u003cp style=\"color:red\"\u003e⚠️ Warning: Since this project has simplified the \"URL signature\" function of imgproxy, please be cautious with the use of Base64-encoded URLs. Malicious actors could exploit this to process images from any untrusted sources for unethical purposes.\u003c/p\u003e\n\n\u003e Image with no preset (it is resized to max-width=1600 as default).\u003cbr/\u003e\n\u003e http://localhost/@base64/aHR0cHM6Ly9tYXJzLm5hc2EuZ292L3N5c3RlbS9kb3dubG9hZGFibGVfaXRlbXMvNDAzNjglNUZQSUEyMjIyOC5qcGc=\n\n\n\u003e The image with preset `_w200` applied (`200` is a dynamic number).\u003cbr/\u003e\n\u003e http://localhost/@base64/_w200/aHR0cHM6Ly9tYXJzLm5hc2EuZ292L3N5c3RlbS9kb3dubG9hZGFibGVfaXRlbXMvNDAzNjglNUZQSUEyMjIyOC5qcGc=\n\n\n\u003e The image with preset `_blurry` applied.\u003cbr/\u003e\n\u003e http://localhost/@base64/_blurry/aHR0cHM6Ly9tYXJzLm5hc2EuZ292L3N5c3RlbS9kb3dubG9hZGFibGVfaXRlbXMvNDAzNjglNUZQSUEyMjIyOC5qcGc=\n\n\n\u003e The image with preset `_small` applied.\u003cbr/\u003e\n\u003e http://localhost/@base64/_small/aHR0cHM6Ly9tYXJzLm5hc2EuZ292L3N5c3RlbS9kb3dubG9hZGFibGVfaXRlbXMvNDAzNjglNUZQSUEyMjIyOC5qcGc=\n\n\n\u003e The image with preset `_medium` applied.\u003cbr/\u003e\n\u003e http://localhost/@base64/_medium/aHR0cHM6Ly9tYXJzLm5hc2EuZ292L3N5c3RlbS9kb3dubG9hZGFibGVfaXRlbXMvNDAzNjglNUZQSUEyMjIyOC5qcGc=\n\n\n\u003e The image with preset `_thumb` applied.\u003cbr/\u003e\n\u003e http://localhost/@base64/_thumb/aHR0cHM6Ly9tYXJzLm5hc2EuZ292L3N5c3RlbS9kb3dubG9hZGFibGVfaXRlbXMvNDAzNjglNUZQSUEyMjIyOC5qcGc=\n\n\n\u003e The image with preset `_square` applied.\u003cbr/\u003e\n\u003e http://localhost/@base64/_square/aHR0cHM6Ly9tYXJzLm5hc2EuZ292L3N5c3RlbS9kb3dubG9hZGFibGVfaXRlbXMvNDAzNjglNUZQSUEyMjIyOC5qcGc=\n\n\n\u003e The image with preset `_masked` applied.\u003cbr/\u003e\n\u003e http://localhost/@base64/_masked/aHR0cHM6Ly9tYXJzLm5hc2EuZ292L3N5c3RlbS9kb3dubG9hZGFibGVfaXRlbXMvNDAzNjglNUZQSUEyMjIyOC5qcGc=\n\n\n\u003e Or just to download the image (with filters applied).\u003cbr/\u003e\n\u003e http://localhost/@base64/_download/aHR0cHM6Ly9tYXJzLm5hc2EuZ292L3N5c3RlbS9kb3dubG9hZGFibGVfaXRlbXMvNDAzNjglNUZQSUEyMjIyOC5qcGc=\n\n\n### Customize resizing via query string\n\n#### Image width and height\n\nYou can also parse arguments from the request's query string, such as `?width=300` for the image's width or `?height=200` for the image's height, or even both of demensions, to flexibly change some parameters for resizing.\n\nIn this setup example, I used the `width` and `height` arguments to override the existing presets.\n\n\u003e Image with specific demensions (1200x960).\u003cbr/\u003e\n\u003e http://localhost/@nasa/40368_PIA22228.jpg?width=1200\u0026height=960\n\n\u003e Image with `width` is set to 500px.\u003cbr/\u003e\n\u003e http://localhost/@nasa/40368_PIA22228.jpg?width=500\n\n\u003e Image with `height` is set to 500px.\u003cbr/\u003e\n\u003e http://localhost/@nasa/40368_PIA22228.jpg?height=500\n\n\u003e The image with preset `_medium` applied, but the query string will override the dimensions of the output image to 50x200px.\u003cbr/\u003e\n\u003e http://localhost/@nasa/_medium/40368_PIA22228.jpg?width=50\u0026height=200\n\n#### Image quality\n\nIn addition, you can override the default quality defined by `IMGPROXY_FORMAT_QUALITY` in the `docker-compose.yml` file by passing a `quality` value (ranging from 1 to 100) in the query string of the request. For example, adding `?quality=100` will set the output image quality to 100% (the best quality).\n\n\u003e Image with `quality` is set.\u003cbr/\u003e\n\u003e You can check the download size of the image using browser's Developer Tools.\u003cbr/\u003e\n\u003e http://localhost/cacti.jpg?quality=1\n\u003e\n\u003e http://localhost/cacti.jpg?quality=10\n\u003e\n\u003e http://localhost/cacti.jpg?quality=50\n\u003e\n\u003e http://localhost/cacti.jpg?quality=80\n\u003e\n\u003e http://localhost/cacti.jpg?quality=100\n\n\u003e Image quality with a human readable `quality` value.\u003cbr/\u003e\n\u003e You can check the download size of the image using browser's Developer Tools.\u003cbr/\u003e\n\u003e http://localhost/cacti.jpg?quality=low\n\u003e\n\u003e http://localhost/cacti.jpg?quality=clear\n\u003e\n\u003e http://localhost/cacti.jpg?quality=high\n\u003e\n\u003e http://localhost/cacti.jpg?quality=highest\n\n\u003e You can combine the `quality` option with any above preset.\u003cbr/\u003e\n\u003e http://localhost/_medium/cacti.jpg?quality=high\n\u003e\n\u003e http://localhost/_blurry/cacti.jpg?width=500\u0026height=500\u0026quality=1\n\nSee [my configurations](#advanced-settings) to know how it works.\n\n---\n\n\n## Debugging\n\n\n### Debugging rewrite rule:\n\nWhen you make a request with the query component `debug=1`, you will see an `X-Debug` header contains its internal `imgproxy`'s options.\n\nExample 1 (local file with preset `_small`):\n```\ncurl -Isk 'http://localhost/_small/cacti.jpg?debug=1'\n\nHTTP/1.1 200 OK\nServer: nginx\nContent-Type: image/webp\nX-Debug: /unsafe/size:320:320:0:0/sharpen:0.3/preset:logo/dpr:1/plain/local:///cacti.jpg\n```\n\nExample 2 (remote file with preset `_w640`):\n```\ncurl -Isk 'http://localhost/@nasa/_w640/40368_PIA22228.jpg?debug=1'\n\nHTTP/1.1 200 OK\nServer: nginx\nContent-Type: image/webp\nX-Debug: /unsafe/size:640:0:0:0/preset:logo/dpr:1/plain/https://mars.nasa.gov/system/downloadable_items/40368_PIA22228.jpg\n```\n\n\n### Debugging fallback image:\n\nWhen you requested a file which is not available, a fallback image will be served.\nThere will be a 404 response with a header called `X-Fallback`, which contains the fallback image's path.\n\n```\ncurl -Isk 'http://localhost/i-am-a-teacup.jpg'\n\nHTTP/1.1 404 Not Found\nServer: nginx\nContent-Type: image/jpeg\nX-Fallback: /noimage.jpg\n```\n\n\n### Other helper URL parameters:\n\nWe can use these URL query components to modify some requests.\n\n\u003e `skip=1`\u003cbr/\u003e\n\u003e Skip imgproxy processing for current request. The original file will be served.\u003cbr/\u003e\n\u003e E.g. http://localhost/_small/cacti.jpg?skip=1 \u003cbr/\u003e\n\u003e E.g. http://localhost/@nasa/_small/40368_PIA22228.jpg?skip=1\n\n\u003e `nocache=1`\u003cbr/\u003e\n\u003e Disable Nginx caching for current request. The response will not be saved to a cache.\u003cbr/\u003e\n\u003e E.g. http://localhost/cacti.jpg?nocache=1 \u003cbr/\u003e\n\u003e E.g. http://localhost/@nasa/40368_PIA22228.jpg?nocache=1\n\n\u003e `bypass=1`\u003cbr/\u003e\n\u003e By pass Nginx caching for current request. The response will not be taken from a cache.\u003cbr/\u003e\n\u003e E.g. http://localhost/_small/cacti.jpg?bypass=1 \u003cbr/\u003e\n\u003e E.g. http://localhost/@nasa/_small/40368_PIA22228.jpg?bypass=1\n\nIf you like this setup, please [support my works](#support-my-activities) 😉.\n\n---\n\n\n## Configurations\n\n\n### Enabling SSL (and HTTP/2)\n\nCreate a folder `certs/` in the same place with the `docker-compose.yml` file, then rename and put your SSL certificates `server.crt` and `server.key` to that `certs/` folder.\n\nOpen the file at [`nginx/nginx.conf`](nginx/nginx.conf#L120~L124) and uncomment 4 lines right after the `# SSL` line, like this:\n\n```nginx\n# SSL\nlisten              443 ssl http2 reuseport;\nlisten              [::]:443 ssl http2 reuseport;\nssl_certificate     /etc/nginx/certs/server.crt;\nssl_certificate_key /etc/nginx/certs/server.key;\n```\n\nThen run the command in the [Start the server](#start-the-server) section to recreate and restart the service.\n\n\n### Serving files from private storage\n\nPlease uncomment settings in `docker-compose.yml` file to enable serving files from [Amazon S3 buckets](docker-compose.yml#L177~L182), [Google Cloud](docker-compose.yml#L184~L187) or [Azure Blob](docker-compose.yml#L189~L194), etc. Then run the command in the [Start the server](#start-the-server) section to recreate and restart the service.\n\nYou can find more details on [imgproxy documentation](https://docs.imgproxy.net/configuration/options?#image-sources).\n\n\n### Flushing cache files\n\nJust remove the folder `cache/`.\n\n```shell\nrm -rf cache/\n```\n\nThen run the command in the [Start the server](#start-the-server) section to restart the service.\n\n\n### Advanced settings\n\nAll settings for handling image URLs are written in the [`imgproxy.conf`](imgproxy.conf#L70~L295) file using [Nginx's map directives](https://Nginx.org/en/docs/http/ngx_http_map_module.html#directives).\n\nI keep all configurations in very simple variables. You can also make your own version from this base.\n\n\n\u003e **`$use_imgproxy`**\u003cbr/\u003e\n\u003e This flag indicates that the request will be proceeded by `imgproxy`.\n\u003e ```nginx\n\u003e map $uri_omitted_origin_preset $use_imgproxy\n\u003e {\n\u003e     default 0;\n\u003e\n\u003e     # Add any rules that you want to skip image processing.\n\u003e     #\u003e E.g. this line excludes files under \"hq-cactus\" folder.\n\u003e     ~^/hq-cactus/ 0;\n\u003e\n\u003e     # File URL is base64-encoded\n\u003e     #\u003e Warning: Since this project has simplified the \"URL signature\" function of imgproxy,\n\u003e     #\u003e please be cautious with the use of Base64-encoded URLs.\n\u003e     #\u003e Malicious actors could exploit this to process images from any untrusted sources for unethical purposes.\n\u003e     #\u003e Comment out these two lines to disable Base64-encoded URLs.\n\u003e     ~^/@base64/         1;\n\u003e     ~[-A-Za-z0-9+/]*=*$ 1;\n\u003e\n\u003e     # Else, process all image files with these file extensions\n\u003e     ~*\\.(jpe?g|png|gif|tiff?|bmp)$  1;\n\u003e }\n\u003e ```\n\n\n\u003e **`$origin_server`**\u003cbr/\u003e\n\u003e Define origin base URL from the request.\n\u003e This setup assumes that an origin server starts with an `@` symbol (such as `@nasa`, `@pinterest`, etc.).\n\u003e You can also add your own origin servers using [regular expressions](https://www.nginx.com/blog/regular-expression-tester-nginx/).\n\u003e ```nginx\n\u003e map $uri $origin_server\n\u003e {\n\u003e     default         'local://';\n\u003e\n\u003e     # Put your rewrite rules for origin servers from here.\n\u003e     #\u003e E.g.\n\u003e     ~^/@mybucket/   's3://my-bucket';\n\u003e     ~^/@myhost/     'http://myhost.com';\n\u003e     ~^/@nasa/       'https://mars.nasa.gov/system/downloadable_items';\n\u003e     ~^/@pinterest/  'https://i.pinimg.com/originals';\n\u003e\n\u003e     # Source URL can be encoded with URL-safe Base64 (please be cautious!)\n\u003e     #\u003e See: https://docs.imgproxy.net/usage/processing#source-url\n\u003e     #\u003e Warning: Since this project has simplified the \"URL signature\" function of imgproxy,\n\u003e     #\u003e please be cautious with the use of Base64-encoded URLs.\n\u003e     #\u003e Malicious actors could exploit this to process images from any untrusted sources for unethical purposes.\n\u003e     #\u003e Comment out the below line to disable Base64-encoded URLs.\n\u003e     ~^/@base64/     ''; # no origin server\n\u003e }\n\u003e ```\n\n\n\u003e **`$origin_uri`**\u003cbr/\u003e\n\u003e Parse real origin URI of the file.\n\u003e This setup just omits origin server and preset name in the URI if they exist,\n\u003e but you can also rewrite requested URI using [regular expressions](https://www.nginx.com/blog/regular-expression-tester-nginx/).\n\u003e ```nginx\n\u003e map $uri_omitted_origin_preset $origin_uri\n\u003e {\n\u003e     default '$uri_omitted_origin_preset';\n\u003e\n\u003e     # Put your rewrite rules for origin URI from here.\n\u003e     #\u003e E.g. this line rewrites cactus.jpg to the real path cacti.jpg.\n\u003e     ~*^/cactus\\.jpe?g$  '/cacti.jpg';\n\u003e }\n\u003e ```\n\n\n\u003e **`$preset_name`**\u003cbr/\u003e\n\u003e Parse preset name from requested URI.\n\u003e This setup assumes that preset name starts with an underscore (`_`) symbol (such as `_thumb` or `_w200`).\n\u003e You can define your own presets using [regular expressions](https://www.nginx.com/blog/regular-expression-tester-nginx/).\n\u003e ```nginx\n\u003e map $uri_omitted_origin $preset_name\n\u003e {\n\u003e     default '';\n\u003e\n\u003e     # You can define dynamic presets,\n\u003e     #\u003e but beware that dynamic presets are able to cause a denial-of-service attack\n\u003e     #\u003e by allowing an attacker to request multiple different image resizes.\n\u003e     #\u003e E.g. a dynamic preset with a variable $width.\n\u003e     # ~^/_w(?\u003cparsed_width\u003e[0-9_-]+)/  'max_w:${parsed_width}';\n\u003e\n\u003e     # This is a better version for above dynamic preset.\n\u003e     #\u003e It allows only certain image sizes,\n\u003e     #\u003e and fallbacks other undefined image sizes to max_w:200\n\u003e     ~^/_w(?\u003cparsed_width\u003e(200|640|800|1200|1600))/  'max_w:${parsed_width}';\n\u003e     ~^/_w(?\u003cparsed_width\u003e([0-9_-]+))/               'max_w:200';\n\u003e\n\u003e     # Get static preset name from the URI\n\u003e     ~^/_(?\u003cparsed_name\u003e[a-z0-9_-]+)/ '$parsed_name';\n\u003e }\n\u003e ```\n\n\n\u003e **`$imgproxy_preset`**\u003cbr/\u003e\n\u003e Define `imgproxy` options for each preset name.\n\u003e You can view more details by following [their documentation](https://docs.imgproxy.net/usage/processing?#processing-options).\n\u003e ```nginx\n\u003e map $preset_name $imgproxy_preset\n\u003e {\n\u003e     default 'size:1600:0:0:0/preset:logo'; # preset:logo adds watermark to the image\n\u003e\n\u003e     # Dynamic preset\n\u003e     ~^max_w:(?\u003cwidth\u003e[0-9]+)$ 'size:${width}:0:0:0/preset:logo';\n\u003e\n\u003e     # Static presets\n\u003e     blurry   'size:320:320:1:0/blur:10/quality:50';\n\u003e     small    'size:320:320:0:0/sharpen:0.3/preset:logo';\n\u003e     medium   'size:640:640:0:0/preset:logo';\n\u003e     thumb    'size:160:160:1:1/bg:ffffff/resizing_type:fill/sharpen:0.3';\n\u003e     square   'size:500:500:0:1/bg:ffffff/resizing_type:fill/preset:logo';\n\u003e     masked   'size:500:0:0:1/bg:ffffff/resizing_type:fill/preset:repeated_logo';\n\u003e     download 'size:1600:0:0:0/preset:logo/return_attachment:1';\n\u003e }\n\u003e ```\n\n\n\u003e **`$imgproxy_preset_query` (overriding presets with query string)**\u003cbr/\u003e\n\u003e Override the `$imgproxy_preset` whenever `width` or `height` provided.\n\u003e But beware that dynamic image sizes are able to cause a denial-of-service attack by allowing an attacker to request multiple different image resizes.\n\u003e ```nginx\n\u003e map \"$arg_width:$arg_height\" $imgproxy_preset_query\n\u003e {\n\u003e     default '';\n\u003e\n\u003e     # only width\n\u003e     ~^(?\u003cwidth\u003e[0-9]+):$ '/size:${width}:0:1:0/bg:ffffff/resizing_type:fill';\n\u003e\n\u003e     # only height\n\u003e     ~^:(?\u003cheight\u003e[0-9]+)$ '/size:0:${height}:1:0/bg:ffffff/resizing_type:fill';\n\u003e\n\u003e     # both width and height\n\u003e     ~^(?\u003cwidth\u003e[0-9]+):(?\u003cheight\u003e[0-9]+)$ '/size:${width}:${height}:1:0/bg:ffffff/resizing_type:fill';\n\u003e }\n\u003e ```\n\n\n\u003e **`$imgproxy_quality` (overriding photo quality with query string)**\u003cbr/\u003e\n\u003e Control photo quality with query string. You can also add your custom settings.\n\u003e ```nginx\n\u003e map $arg_quality $imgproxy_quality\n\u003e {\n\u003e     default '';\n\u003e\n\u003e     # if the given value is between 1 and 100, override the quality\n\u003e     ~^(?\u003cquality\u003e[1-9][0-9]?|100)$ '/q:${quality}';\n\u003e\n\u003e     # or receive some readable quality values\n\u003e     low         '/q:30';\n\u003e     clear       '/q:50';\n\u003e     high        '/q:80';\n\u003e     highest     '/q:100';\n\u003e }\n\u003e ```\n\n\n\u003e **`$imgproxy_dpr` (controlling photo dimensions, aka Device Pixel Ratio)**\u003cbr/\u003e\n\u003e This will multiplying the image dimensions according to this factor for HiDPI (Retina) devices.\n\u003e ```nginx\n\u003e map $http_user_agent@$http_dpr $imgproxy_dpr\n\u003e {\n\u003e     default '/dpr:1';\n\u003e\n\u003e     # parse from DPR header\n\u003e     ~@(?\u003cdpr\u003e[1-4])     '/dpr:${dpr}';\n\u003e\n\u003e     # Put your rewrite rules for DPR settings from here.\n\u003e     #\u003e E.g. these lines will set custom DPR for smartphones.\n\u003e     # ~iPhone|iPad|Mac    '/dpr:3';\n\u003e     # ~Android            '/dpr:2';\n\u003e }\n\u003e ```\n\n\n\u003e **`$imgproxy_options`**\u003cbr/\u003e\n\u003e Generate final URL for `imgproxy` following [their documentation](https://docs.imgproxy.net/usage/processing).\n\u003e When URL query `?skip=1` is set, use another rule to skip `imgproxy` processing.\n\u003e ```nginx\n\u003e map $arg_skip $imgproxy_options\n\u003e {\n\u003e     default '/unsafe/${imgproxy_preset}${imgproxy_preset_query}${imgproxy_quality}${imgproxy_dpr}${imgproxy_type}/${origin_server}${origin_uri}${imgproxy_extension}';\n\u003e     ~.+     '/unsafe${imgproxy_type}/${origin_server}${origin_uri}';\n\u003e }\n\u003e ```\n\n\n\u003e **`$fallback_uri`**\u003cbr/\u003e\n\u003e Define fallback file to serve when the requested file is unavailable.\n\u003e E.g. `/noimage.jpg` or `/noimage_thumb.jpg`, which is stored in the folder `www/`.\n\u003e ```nginx\n\u003e map $preset_name $fallback_uri\n\u003e {\n\u003e     default '/noimage.jpg';\n\u003e     thumb   '/noimage_thumb.jpg';\n\u003e     # small   '/noimage_small.jpg';\n\u003e     # medium  '/noimage_medium.jpg';\n\u003e     # square  '/noimage_square.jpg';\n\u003e }\n\u003e ```\n\n\nI think you can even make a better version than mine 😊.\n\n\n* * *\n\nIf you like this project, please [support my works](#support-my-activities) 😉.\n\nFrom Vietnam 🇻🇳 with love.\n","funding_links":["https://github.com/sponsors/shinsenter","https://www.paypal.me/shinsenter"],"categories":["Dockerfile"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinsenter%2Fdocker-imgproxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinsenter%2Fdocker-imgproxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinsenter%2Fdocker-imgproxy/lists"}