This is an Nginx reverse Proxy that works with Traefik and is configurable via ENV variables.
248
Deploys a proxy using Nginx and Traefik.
<dynamic subdomain>.YOUR_DOMAIN<dynamic_subdomain>.YOUR_TARGETThis package allows you to dynamically get the bucket URL from the incoming request subdomain and forward it as the proxy pass.
MyBucketName.your_domain.com will become MyBucketName.s3.myprovider.com
This way you can use a single proxy for multiple buckets as long as they exist on the same TLD.
Example docker-compose.yml:
(This assumes you have Traefik alrady in running in a different Stack)
version: "3.4"
networks:
traefik:
external: true
volumes:
proxy_cache:
services:
proxy:
container_name: proxy
image: kevingregull/traefik_nginx_proxy
restart: unless-stopped
expose:
- 1337
labels:
- "traefik.enable=true"
- "traefik.http.routers.proxy_example.rule=HostRegexp(`^[a-zA-z0-9-]+\\.<YOUR_DOMAIN>`)"
- "traefik.http.routers.proxy_example.entrypoints=<YOUR_ENTRYPOINT>"
- "traefik.http.routers.proxy_example.tls.certresolver=<YOUR_CERT_RESOLVER>"
- "traefik.http.routers.proxy_example.tls.domains[0].main=*.<YOUR_DOMAIN>"
- "traefik.http.routers.proxy_example.service=proxy_example_srv"
- "traefik.http.services.proxy_example_srv.loadbalancer.server.port=1337"
volumes:
- proxy_cache:/data/nginx/cache
environment:
- "CACHE_DOMAIN=<YOUR_DOMAIN>" # This is the domain that you want to host your cache on
- "CACHE_TARGET=<YOUR_TARGET>" # This is the Domain to your actual content s3.myprovider.com (without the bucket url)
networks:
- traefik
Required Environment Variables:
# The domain that you want to host your cache on
ENV CACHE_DOMAIN
# The Domain to your actual content s3.myprovider.com (without the bucket url)
ENV CACHE_TARGET
Optional Configuration Environment Variables:
# Environment Variables
#worker_processes ${SERVER_WORKER_PROCESSES};
# How many Worker Processes should Nginx use - "The optimal value depends on many factors including (but not limited to) the number of CPU cores, the number of hard disk drives that store data, and load pattern."
ENV SERVER_WORKER_PROCESSES="auto"
#worker_connections ${SERVER_WORKER_CONNECTIONS};
# How many Connections should Nginx accept at the same time
ENV SERVER_WORKER_CONNECTIONS="4096"
#use ${SERVER_POLLING};
# How should Nginx process Connections - select, poll, epoll - "epoll is the recommended option on Linux 2.6 and later"
ENV SERVER_POLLING="epoll"
#multi_accept ${SERVER_MULTI_ACCEPT};
# Only turn on when you expect a lot of traffic - "If enabled, worker processes will accept new connections by turn."
ENV SERVER_MULTI_ACCEPT="off"
#resolver ${SERVER_RESOLVER};
# Because the proxy_pass is dynamic we need to specify a DNS resolver for it - standard is cloudflare (Google is 8.8.8.8)
ENV SERVER_RESOLVER="1.1.1.1"
#proxy_cache_path ${CACHE_PATH} levels=${CACHE_LEVELS} keys_zone=STATIC:${CACHE_META_SIZE} inactive=${CACHE_INACTIVE} max_size=${CACHE_MAX_SIZE};
# The Filepath where Nginx should store the cached Files - If you want a persistent Cache, mount a Volume to this Path
ENV CACHE_PATH="/data/nginx/cache"
# How many Subdirectories should be created in the Cache Path
ENV CACHE_LEVELS="1:2"
# How big should the Memory Metadata storage be - "One megabyte zone can store about 8 thousand keys"
ENV CACHE_META_SIZE="50m"
# What should the max size of the cache be. If the cache is full, the oldest files will be deleted
ENV CACHE_MAX_SIZE="10g"
# After how long should a file be deleted from the cache if it was not accessed
ENV CACHE_INACTIVE="7d"
#proxy_buffering ${PROXY_BUFFERING};
# Should Nginx buffer files on disk before sending them to the client
ENV PROXY_BUFFERING="off"
#proxy_cache_background_update ${PROXY_CACHE_BACKGROUND_UPDATE};
# Should Nginx update the cached file in the background after it was served to the client
ENV PROXY_CACHE_BACKGROUND_UPDATE="on"
#proxy_cache_lock ${PROXY_CACHE_LOCK};
# Should Nginx lock the cached file while it is being updated
ENV PROXY_CACHE_LOCK="on"
#proxy_cache_lock_age ${PROXY_CACHE_LOCK_AGE};
# How long should Nginx wait before it tries to update the cached file again
ENV PROXY_CACHE_LOCK_AGE="2s"
#proxy_cache_lock_timeout ${PROXY_CACHE_LOCK_TIMEOUT};
# How long should Nginx wait before it gives up on updating the cached file
ENV PROXY_CACHE_LOCK_TIMEOUT="2s"
#proxy_cache_min_uses ${PROXY_CACHE_MIN_USES};
# How many times should a file be requested before it is cached
ENV PROXY_CACHE_MIN_USES="1"
#proxy_cache_valid 200 302 ${PROXY_CACHE_VALID};
# How long should a valid file be cached after it was requested
ENV PROXY_CACHE_VALID="1d"
#proxy_cache_valid any ${PROXY_CACHE_VALID_ANY};
# How long should a invalid response be cached after it was requested
ENV PROXY_CACHE_VALID_ANY="5m"
#proxy_cache_use_stale ${PROXY_CACHE_USE_STALE};
# When should Nginx use a cached file even if it is outdated
ENV PROXY_CACHE_USE_STALE="error timeout invalid_header updating http_500 http_502 http_503 http_504"
Content type
Image
Digest
sha256:467319ca4…
Size
67.3 MB
Last updated
almost 3 years ago
docker pull kevingregull/traefik_nginx_proxy