diff --git a/Dockerfile b/Dockerfile index f12f3a1..394ad68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,9 @@ ENV GENERICCACHE_VERSION=2 \ CACHE_DOMAINS_BRANCH=master \ NGINX_WORKER_PROCESSES=auto +RUN apt-get update ;\ + apt-get install -y jq git ; + COPY overlay/ / RUN rm /etc/nginx/sites-enabled/* /etc/nginx/stream-enabled/* ;\ @@ -31,12 +34,11 @@ RUN rm /etc/nginx/sites-enabled/* /etc/nginx/stream-enabled/* ;\ chown -R ${WEBUSER}:${WEBUSER} /data/ ;\ mkdir -p /etc/nginx/sites-enabled ;\ ln -s /etc/nginx/sites-available/10_cache.conf /etc/nginx/sites-enabled/10_generic.conf; \ + ln -s /etc/nginx/sites-available/upstream.conf /etc/nginx/sites-enabled/upstream.conf; \ ln -s /etc/nginx/stream-available/10_sni.conf /etc/nginx/stream-enabled/10_sni.conf RUN mkdir -m 755 -p /data/cachedomains ;\ - mkdir -m 755 -p /tmp/nginx ;\ - apt-get update ;\ - apt-get install -y jq git ; + mkdir -m 755 -p /tmp/nginx RUN git clone --depth=1 --no-single-branch https://github.com/uklans/cache-domains/ /data/cachedomains diff --git a/overlay/etc/nginx/nginx.conf b/overlay/etc/nginx/nginx.conf index 367a734..3875442 100644 --- a/overlay/etc/nginx/nginx.conf +++ b/overlay/etc/nginx/nginx.conf @@ -25,6 +25,7 @@ http { error_log /var/log/nginx/error.log; + gzip on; include /etc/nginx/conf.d/*.conf; diff --git a/overlay/etc/nginx/sites-available/cache.conf.d/root/20_cache.conf b/overlay/etc/nginx/sites-available/cache.conf.d/root/20_cache.conf index 263b874..4fb1ce4 100644 --- a/overlay/etc/nginx/sites-available/cache.conf.d/root/20_cache.conf +++ b/overlay/etc/nginx/sites-available/cache.conf.d/root/20_cache.conf @@ -31,5 +31,3 @@ # 40G max file proxy_max_temp_file_size 40960m; - - diff --git a/overlay/etc/nginx/sites-available/cache.conf.d/root/90_upstream.conf b/overlay/etc/nginx/sites-available/cache.conf.d/root/90_upstream.conf index a42a604..31b435b 100644 --- a/overlay/etc/nginx/sites-available/cache.conf.d/root/90_upstream.conf +++ b/overlay/etc/nginx/sites-available/cache.conf.d/root/90_upstream.conf @@ -1,6 +1,8 @@ # Upstream Configuration proxy_next_upstream error timeout http_404; - proxy_pass http://$host$request_uri; +# proxy_pass http://$host$request_uri; + proxy_pass http://127.0.0.1:3128$request_uri; + proxy_redirect off; proxy_ignore_client_abort on; diff --git a/overlay/etc/nginx/sites-available/upstream.conf b/overlay/etc/nginx/sites-available/upstream.conf new file mode 100644 index 0000000..daebbc2 --- /dev/null +++ b/overlay/etc/nginx/sites-available/upstream.conf @@ -0,0 +1,23 @@ +server { + listen 3128 reuseport; + + set $orig_loc 'upstream'; + +# access_log /data/logs/upstream-access.log cachelog; + error_log /data/logs/upstream-error.log; + + resolver UPSTREAM_DNS ipv6=off; + + location / { + proxy_pass http://$host$request_uri; + proxy_intercept_errors on; + error_page 301 302 307 = @upstream_redirect; + } + + location @upstream_redirect { + set $saved_upstream_location '$upstream_http_location'; + set $orig_loc 'upstream-302'; + + proxy_pass $saved_upstream_location; + } +} diff --git a/overlay/hooks/entrypoint-pre.d/10_setup.sh b/overlay/hooks/entrypoint-pre.d/10_setup.sh index f9a9d0e..5a33d13 100644 --- a/overlay/hooks/entrypoint-pre.d/10_setup.sh +++ b/overlay/hooks/entrypoint-pre.d/10_setup.sh @@ -18,3 +18,4 @@ sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/sites-available/cache.c sed -i "s/slice 1m;/slice ${CACHE_SLICE_SIZE};/" /etc/nginx/sites-available/cache.conf.d/root/20_cache.conf sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/cache.conf.d/10_root.conf sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/stream-available/10_sni.conf +sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/upstream.conf