From 963c20c60c05f696ff88dff1c9d372e25f069895 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Tue, 8 Feb 2022 21:32:12 -0500 Subject: [PATCH] nginx configuration to serve files --- docker/app/run-development | 10 +++++----- docker/web/Dockerfile | 3 ++- docker/web/nginx.conf | 30 ++++++++++++++++++++---------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/docker/app/run-development b/docker/app/run-development index 5e171745..90a315d6 100755 --- a/docker/app/run-development +++ b/docker/app/run-development @@ -2,11 +2,11 @@ # Create S3 dirs mkdir -p /srv/philomena/priv/s3/philomena -ln -s /srv/philomena/priv/system/images/thumbs /srv/philomena/priv/s3/philomena/images -ln -s /srv/philomena/priv/system/images /srv/philomena/priv/s3/philomena/adverts -ln -s /srv/philomena/priv/system/images /srv/philomena/priv/s3/philomena/avatars -ln -s /srv/philomena/priv/system/images /srv/philomena/priv/s3/philomena/badges -ln -s /srv/philomena/priv/system/images /srv/philomena/priv/s3/philomena/tags +ln -sf /srv/philomena/priv/static/system/images/thumbs /srv/philomena/priv/s3/philomena/images +ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/adverts +ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/avatars +ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/badges +ln -sf /srv/philomena/priv/static/system/images /srv/philomena/priv/s3/philomena/tags # For compatibility with musl libc export CARGO_FEATURE_DISABLE_INITIAL_EXEC_TLS=1 diff --git a/docker/web/Dockerfile b/docker/web/Dockerfile index bf79c468..e76dab63 100644 --- a/docker/web/Dockerfile +++ b/docker/web/Dockerfile @@ -1,6 +1,7 @@ FROM nginx:1.21.4-alpine ENV APP_DIR /srv/philomena +ENV BUCKET_NAME philomena COPY docker/web/nginx.conf /tmp/docker.nginx -RUN envsubst '$APP_DIR' < /tmp/docker.nginx > /etc/nginx/conf.d/default.conf +RUN envsubst '$APP_DIR $BUCKET_NAME' < /tmp/docker.nginx > /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] diff --git a/docker/web/nginx.conf b/docker/web/nginx.conf index c7e9f26d..012d6fa6 100644 --- a/docker/web/nginx.conf +++ b/docker/web/nginx.conf @@ -2,6 +2,10 @@ upstream philomena { server app:4000 fail_timeout=0; } +upstream s3 { + server files:80 fail_timeout=0; +} + server { listen 80 default; listen [::]:80; @@ -14,38 +18,44 @@ server { location ~ ^/img/view/(.+)/([0-9]+).*\.([A-Za-z0-9]+)$ { expires max; add_header Cache-Control public; - alias "$APP_DIR/priv/static/system/images/thumbs/$1/$2/full.$3"; + proxy_pass http://s3/$BUCKET_NAME/images/$1/$2/full.$3; } location ~ ^/img/download/(.+)/([0-9]+).*\.([A-Za-z0-9]+)$ { add_header Content-Disposition "attachment"; expires max; add_header Cache-Control public; - alias "$APP_DIR/priv/static/system/images/thumbs/$1/$2/full.$3"; + proxy_pass http://s3/$BUCKET_NAME/images/$1/$2/full.$3; } - location ~ ^/img/(.+) { + location ~ ^/img/(.+) { expires max; add_header Cache-Control public; - alias $APP_DIR/priv/static/system/images/thumbs/$1; + proxy_pass http://s3/$BUCKET_NAME/images/$1; } - location ~ ^/spns/(.+) { + location ~ ^/spns/(.+) { expires max; add_header Cache-Control public; - alias $APP_DIR/priv/static/system/images/adverts/$1; + proxy_pass http://s3/$BUCKET_NAME/adverts/$1; } - location ~ ^/avatars/(.+) { + location ~ ^/avatars/(.+) { expires max; add_header Cache-Control public; - alias $APP_DIR/priv/static/system/images/avatars/$1; + proxy_pass http://s3/$BUCKET_NAME/avatars/$1; } - location ~ ^/media/(.+) { + location ~ ^/badges/(.+) { expires max; add_header Cache-Control public; - alias $APP_DIR/priv/static/system/images/$1; + proxy_pass http://s3/$BUCKET_NAME/badges/$1; + } + + location ~ ^/tags/(.+) { + expires max; + add_header Cache-Control public; + proxy_pass http://s3/$BUCKET_NAME/tags/$1; } location / {