mirror of
https://github.com/lancachenet/monolithic
synced 2024-11-25 05:20:17 +00:00
Addition of upstream proxy to resolve slice redirect errors (302 Playstation) (#156)
Addition of Upstream proxy from #60 to test 302 cache impact on PS5 caching Refactored upstream proxy into lancache standard structure. Simplified both location blocks into a single file rather than further delegated folders Fixed spacing & indents
This commit is contained in:
parent
de46e47292
commit
a45516468d
12 changed files with 87 additions and 39 deletions
27
Dockerfile
27
Dockerfile
|
@ -3,6 +3,9 @@ LABEL version=3
|
||||||
LABEL description="Single caching container for caching game content at LAN parties."
|
LABEL description="Single caching container for caching game content at LAN parties."
|
||||||
LABEL maintainer="LanCache.Net Team <team@lancache.net>"
|
LABEL maintainer="LanCache.Net Team <team@lancache.net>"
|
||||||
|
|
||||||
|
RUN apt-get update ;\
|
||||||
|
apt-get install -y jq git ;
|
||||||
|
|
||||||
ENV GENERICCACHE_VERSION=2 \
|
ENV GENERICCACHE_VERSION=2 \
|
||||||
CACHE_MODE=monolithic \
|
CACHE_MODE=monolithic \
|
||||||
WEBUSER=www-data \
|
WEBUSER=www-data \
|
||||||
|
@ -24,19 +27,17 @@ RUN rm /etc/nginx/sites-enabled/* /etc/nginx/stream-enabled/* ;\
|
||||||
chmod 754 /var/log/tallylog ; \
|
chmod 754 /var/log/tallylog ; \
|
||||||
id -u ${WEBUSER} &> /dev/null || adduser --system --home /var/www/ --no-create-home --shell /bin/false --group --disabled-login ${WEBUSER} ;\
|
id -u ${WEBUSER} &> /dev/null || adduser --system --home /var/www/ --no-create-home --shell /bin/false --group --disabled-login ${WEBUSER} ;\
|
||||||
chmod 755 /scripts/* ;\
|
chmod 755 /scripts/* ;\
|
||||||
mkdir -m 755 -p /data/cache ;\
|
mkdir -m 755 -p /data/cache ;\
|
||||||
mkdir -m 755 -p /data/info ;\
|
mkdir -m 755 -p /data/info ;\
|
||||||
mkdir -m 755 -p /data/logs ;\
|
mkdir -m 755 -p /data/logs ;\
|
||||||
mkdir -m 755 -p /tmp/nginx/ ;\
|
mkdir -m 755 -p /tmp/nginx/ ;\
|
||||||
chown -R ${WEBUSER}:${WEBUSER} /data/ ;\
|
chown -R ${WEBUSER}:${WEBUSER} /data/ ;\
|
||||||
mkdir -p /etc/nginx/sites-enabled ;\
|
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/10_cache.conf /etc/nginx/sites-enabled/10_generic.conf; \
|
||||||
ln -s /etc/nginx/stream-available/10_sni.conf /etc/nginx/stream-enabled/10_sni.conf
|
ln -s /etc/nginx/sites-available/20_upstream.conf /etc/nginx/sites-enabled/20_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 /data/cachedomains ;\
|
||||||
mkdir -m 755 -p /tmp/nginx ;\
|
mkdir -m 755 -p /tmp/nginx
|
||||||
apt-get update ;\
|
|
||||||
apt-get install -y jq git ;
|
|
||||||
|
|
||||||
RUN git clone --depth=1 --no-single-branch https://github.com/uklans/cache-domains/ /data/cachedomains
|
RUN git clone --depth=1 --no-single-branch https://github.com/uklans/cache-domains/ /data/cachedomains
|
||||||
|
|
||||||
|
|
|
@ -5,35 +5,37 @@ pid /run/nginx.pid;
|
||||||
include /etc/nginx/modules-enabled/*.conf;
|
include /etc/nginx/modules-enabled/*.conf;
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections 4096;
|
worker_connections 4096;
|
||||||
multi_accept on;
|
multi_accept on;
|
||||||
use epoll;
|
use epoll;
|
||||||
}
|
}
|
||||||
|
|
||||||
http {
|
http {
|
||||||
aio threads;
|
aio threads;
|
||||||
sendfile on;
|
sendfile on;
|
||||||
tcp_nopush on;
|
tcp_nopush on;
|
||||||
tcp_nodelay on;
|
tcp_nodelay on;
|
||||||
keepalive_timeout 65;
|
keepalive_timeout 65;
|
||||||
types_hash_max_size 2048;
|
types_hash_max_size 2048;
|
||||||
|
|
||||||
include /etc/nginx/mime.types;
|
include /etc/nginx/mime.types;
|
||||||
default_type application/octet-stream;
|
default_type application/octet-stream;
|
||||||
|
|
||||||
access_log /var/log/nginx/access.log;
|
access_log /var/log/nginx/access.log;
|
||||||
error_log /var/log/nginx/error.log;
|
error_log /var/log/nginx/error.log;
|
||||||
|
|
||||||
|
|
||||||
gzip on;
|
|
||||||
|
|
||||||
include /etc/nginx/conf.d/*.conf;
|
gzip on;
|
||||||
|
|
||||||
include /etc/nginx/sites-enabled/*.conf;
|
include /etc/nginx/conf.d/*.conf;
|
||||||
|
|
||||||
|
include /etc/nginx/sites-enabled/*.conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
stream {
|
stream {
|
||||||
include /etc/nginx/stream.d/*.conf;
|
include /etc/nginx/stream.d/*.conf;
|
||||||
include /etc/nginx/stream-enabled/*;
|
include /etc/nginx/stream-enabled/*;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# Primary monolithic cache engine
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80 reuseport;
|
listen 80 reuseport;
|
||||||
|
|
||||||
|
|
17
overlay/etc/nginx/sites-available/20_upstream.conf
Normal file
17
overlay/etc/nginx/sites-available/20_upstream.conf
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# Upstream server to proxy and handle inconsistent 302 redirects
|
||||||
|
# All cache traffic is passed through this proxy to allow rewriting of redirects without caching
|
||||||
|
|
||||||
|
# This is particularly important for sony / ps5 as upstreams redirect between them which confuses slice map on caching
|
||||||
|
|
||||||
|
server {
|
||||||
|
|
||||||
|
# Internal bind on 3128, this should not be externally mapped
|
||||||
|
listen localhost:3128 reuseport;
|
||||||
|
|
||||||
|
# No access_log tracking as all requests to this instance are already logged through monolithic
|
||||||
|
|
||||||
|
# access_log /data/logs/upstream-access.log cachelog;
|
||||||
|
error_log /data/logs/upstream-error.log;
|
||||||
|
|
||||||
|
include /etc/nginx/sites-available/upstream.conf.d/*.conf;
|
||||||
|
}
|
|
@ -31,5 +31,3 @@
|
||||||
|
|
||||||
# 40G max file
|
# 40G max file
|
||||||
proxy_max_temp_file_size 40960m;
|
proxy_max_temp_file_size 40960m;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
# Upstream Configuration
|
# Upstream Configuration
|
||||||
proxy_next_upstream error timeout http_404;
|
proxy_next_upstream error timeout http_404;
|
||||||
proxy_pass http://$host$request_uri;
|
|
||||||
|
# Proxy into the redirect handler
|
||||||
|
proxy_pass http://127.0.0.1:3128$request_uri;
|
||||||
|
|
||||||
proxy_redirect off;
|
proxy_redirect off;
|
||||||
proxy_ignore_client_abort on;
|
proxy_ignore_client_abort on;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
resolver UPSTREAM_DNS ipv6=off;
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Header to track if resolved from upstream or 302 redirect
|
||||||
|
set $orig_loc 'upstream';
|
|
@ -0,0 +1,9 @@
|
||||||
|
# Proxy all requests to upstream
|
||||||
|
location / {
|
||||||
|
# Simple proxy the request
|
||||||
|
proxy_pass http://$host$request_uri;
|
||||||
|
|
||||||
|
# Catch the errors to process the redirects
|
||||||
|
proxy_intercept_errors on;
|
||||||
|
error_page 301 302 307 = @upstream_redirect;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Special location block to handle 302 redirects
|
||||||
|
location @upstream_redirect {
|
||||||
|
# Upstream_http_location contains the Location: redirection from the upstream server
|
||||||
|
set $saved_upstream_location '$upstream_http_location';
|
||||||
|
|
||||||
|
# Set debug header
|
||||||
|
set $orig_loc 'upstream-302';
|
||||||
|
|
||||||
|
# Pass to proxy and reproxy the request
|
||||||
|
proxy_pass $saved_upstream_location;
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
server {
|
server {
|
||||||
listen 443;
|
listen 443;
|
||||||
resolver UPSTREAM_DNS ipv6=off;
|
resolver UPSTREAM_DNS ipv6=off;
|
||||||
proxy_pass $ssl_preread_server_name:443;
|
proxy_pass $ssl_preread_server_name:443;
|
||||||
ssl_preread on;
|
ssl_preread on;
|
||||||
|
|
||||||
access_log /data/logs/stream-access.log stream_basic;
|
access_log /data/logs/stream-access.log stream_basic;
|
||||||
error_log /data/logs/stream-error.log;
|
error_log /data/logs/stream-error.log;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,5 @@ sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/conf.d/20_proxy_cache_path
|
||||||
sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/sites-available/cache.conf.d/root/20_cache.conf
|
sed -i "s/CACHE_MAX_AGE/${CACHE_MAX_AGE}/" /etc/nginx/sites-available/cache.conf.d/root/20_cache.conf
|
||||||
sed -i "s/slice 1m;/slice ${CACHE_SLICE_SIZE};/" /etc/nginx/sites-available/cache.conf.d/root/20_cache.conf
|
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/sites-available/cache.conf.d/10_root.conf
|
||||||
|
sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/sites-available/upstream.conf.d/10_resolver.conf
|
||||||
sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/stream-available/10_sni.conf
|
sed -i "s/UPSTREAM_DNS/${UPSTREAM_DNS}/" /etc/nginx/stream-available/10_sni.conf
|
||||||
|
|
Loading…
Reference in a new issue