Optimizing Costs and Performance with Private Image Optimizer API Using ImgProxy on VPS
A detailed guide on deploying and optimizing a Private Image Optimizer API with ImgProxy on a VPS to reduce costs, improve performance, and enhance web user experience.
Image credit: herbert2512 · Pixabay Content License
Optimizing Costs and Performance with Private Image Optimizer API Using ImgProxy on VPS
In the era of web applications increasingly reliant on images, managing and optimizing images has become a critical factor in improving performance, reducing server load, and saving bandwidth costs. An effective solution is deploying a Private Image Optimizer API using ImgProxy on a VPS. Directly impacting user experience and operational costs, on-demand image processing with automatic format, size, and quality adjustments significantly reduces data traffic and speeds up page load times.
Introduction to ImgProxy and Benefits of Private Image Optimizer API
ImgProxy is an open-source image service designed for high-performance, on-demand image processing. It allows you to generate optimized images (resize, crop, convert, compress) from original images without storing multiple versions. With the Private Image Optimizer API feature, you can protect original images from public access by using a signature key to authenticate requests.
Key benefits of using ImgProxy on a VPS include:
- Reduced bandwidth costs: Only load optimized images on demand, eliminating the need to store multiple versions.
- Improved performance: Images are processed quickly at request time, reducing server load.
- Image security: Original images are not publicly stored; access is only possible via a signed API.
- Enhanced user experience: Images are resized to fit devices, loading faster.
Deploying ImgProxy on VPS with Docker
To deploy ImgProxy, you can use Docker to simplify installation and management. Below are the basic steps to set up a Private Image Optimizer API on a VPS.
Prerequisites
- VPS with Linux OS (Ubuntu 20.04/22.04)
- Docker and Docker Compose installed
- Signature key for API protection (generated from environment)
- URL for original image source (e.g., S3, Google Cloud Storage, or internal server)
docker-compose.yml Configuration File
version: '3.8'
services:
imgproxy:
image: imgproxy/imgproxy:latest
container_name: imgproxy
ports:
- "8080:8080"
environment:
- IMGPROXY_SIGNATURE_KEY=your_secret_signature_key_here
- IMGPROXY_SOURCE_URL=http://your-image-server:8080/images/
- IMGPROXY_SOURCE_PROTOCOL=http
- IMGPROXY_SOURCE_TIMEOUT=10s
- IMGPROXY_LOG_LEVEL=info
restart: unless-stopped
Start the Service
docker-compose up -d
Image Conversion with Private Image Optimizer API
After ImgProxy starts, you can generate optimized image requests using encoded URLs. For example:
https://your-vps-ip:8080/unsafe/fit-in/300x200/your-image-url.jpg
Where:
unsafe: Bypass signature verification (use only in development)fit-in/300x200: Resize image to 300x200 pixels while maintaining aspect ratioyour-image-url.jpg: Original image URL (e.g., S3 or internal address)
Verification and Performance Testing
To verify the service is working correctly, perform the following steps:
1. Check Service Status
docker ps | grep imgproxy
If the service is running, you will see the imgproxy container.
2. Send Test Image Request
curl -s "https://your-vps-ip:8080/unsafe/fit-in/300x200/https://example.com/image.jpg" -o test-image.jpg
If the image is returned and resized to 300x200, the service is working correctly.
3. Test Performance with Tools
Run the following commands to check response time:
time curl -s "https://your-vps-ip:8080/unsafe/fit-in/300x200/https://example.com/image.jpg" > /dev/null
Troubleshooting and Optimization
1. Image Access Issues
- Check if the ImgProxy service is running.
- Ensure the signature key is correctly set.
- Verify the source image URL is correct.
2. Low Performance
- Upgrade VPS resources (CPU, RAM).
- Apply image caching using Redis or Memcached.
- Limit concurrent requests using Nginx or Traefik.
References
Recommended NVMe Cloud VPS Plans to Deploy This Setup
Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.
VPS-3E
10% VAT included
- CPU: 2 vCPU
- RAM: 4 GB
- SSD: 50 GB NVMe
