nginx configuration to serve files

This commit is contained in:
byte[] 2022-02-08 21:32:12 -05:00
parent 577d5e8766
commit 963c20c60c
3 changed files with 27 additions and 16 deletions

View file

@ -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

View file

@ -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;"]

View file

@ -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/(.+) {
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/(.+) {
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/(.+) {
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 / {