Created
January 24, 2018 03:11
-
-
Save fermayo/92a0629a4cd60dd45fde660176fa885d to your computer and use it in GitHub Desktop.
Automatically configure nginx to trust AWS Cloudfront IPs present in X-Fowarded-For
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:latest AS cloudfront | |
RUN apk --no-cache add curl jq | |
RUN curl https://ip-ranges.amazonaws.com/ip-ranges.json | \ | |
jq -r '.prefixes[] | select(.service=="CLOUDFRONT") | .ip_prefix' | \ | |
xargs -I '{}' echo 'set_real_ip_from {};' > /cloudfront.conf && \ | |
echo 'real_ip_header X-Forwarded-For;' >> /cloudfront.conf && \ | |
echo 'real_ip_recursive on;' >> /cloudfront.conf | |
FROM nginx:latest | |
COPY --from=cloudfront /cloudfront.conf /etc/nginx/conf.d/cloudfront.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment