Skip to content

Commit

Permalink
feat(nginx): Enable upstream keepalive (immich-app#1206)
Browse files Browse the repository at this point in the history
* Enable keepalive

* Adapt envsubst

* Fix shellcheck issues

* Lower connection count
  • Loading branch information
otbutz authored Dec 30, 2022
1 parent 10b0924 commit b584185
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 12 additions & 2 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ http {
# worker_connections 1000;
# }

upstream server {
server $IMMICH_SERVER_HOST
keepalive 2
}

upstream web {
server $IMMICH_WEB_HOST
keepalive 2
}

server {

gzip on;
Expand Down Expand Up @@ -61,7 +71,7 @@ http {

rewrite /api/(.*) /$1 break;

proxy_pass $IMMICH_SERVER_URL;
proxy_pass ${IMMICH_SERVER_SCHEME}server;
}

location / {
Expand All @@ -86,7 +96,7 @@ http {
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;

proxy_pass $IMMICH_WEB_URL;
proxy_pass ${IMMICH_WEB_SCHEME}web;
}
}
}
10 changes: 9 additions & 1 deletion nginx/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
set -e

export IMMICH_WEB_URL=${IMMICH_WEB_URL:-http://immich-web:3000}
IMMICH_WEB_SCHEME=$(echo "$IMMICH_WEB_URL" | grep -Eo '^https?://' || echo "http://")
export IMMICH_WEB_SCHEME
IMMICH_WEB_HOST=$(echo "$IMMICH_WEB_URL" | cut -d '/' -f 3)
export IMMICH_WEB_HOST
export IMMICH_SERVER_URL=${IMMICH_SERVER_URL:-http://immich-server:3001}
IMMICH_SERVER_SCHEME=$(echo "$IMMICH_WEB_URL" | grep -Eo '^https?://' || echo "http://")
export IMMICH_SERVER_SCHEME
IMMICH_SERVER_HOST=$(echo "$IMMICH_SERVER_URL" | cut -d '/' -f 3)
export IMMICH_SERVER_HOST

envsubst '$IMMICH_WEB_URL $IMMICH_SERVER_URL' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf
envsubst '$IMMICH_WEB_SCHEME $IMMICH_WEB_HOST $IMMICH_SERVER_SCHEME $IMMICH_SERVER_HOST' < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf

exec nginx -g 'daemon off;'

0 comments on commit b584185

Please sign in to comment.