Skip to content

Instantly share code, notes, and snippets.

@aveexy
Last active January 8, 2025 09:29
Show Gist options
  • Save aveexy/4b2b22b2198636b0a91c7c142ec11b37 to your computer and use it in GitHub Desktop.
Save aveexy/4b2b22b2198636b0a91c7c142ec11b37 to your computer and use it in GitHub Desktop.
immich nginx reverse proxy with base url (not a full/complete nginx config) base url is /immich (if you want something other, replace "/immich" with other path
pid /run/nginx/nginx.pid;
error_log stderr;
daemon off;
events {
}
http {
proxy_cache_path /var/cache/nginx/immich_revprox keys_zone=immich_revprox:10m levels=1:2 use_temp_path=off inactive=1d max_size=1g;
server {
listen 0.0.0.0:443 ssl ;
listen [::0]:443 ssl ;
server_name example.com ;
http2 on;
location /immich {
proxy_pass http://192.168.1.100:2283;
rewrite /immich/(.*) /$1 break;
proxy_set_header Accept-Encoding "gzip";
gunzip on;
proxy_pass_request_headers on;
proxy_buffering on;
proxy_cache immich_revprox;
proxy_cache_valid 200 206 1d;
sub_filter_once off;
sub_filter_types text/html;
sub_filter ' href="/' ' href="/immich/';
sub_filter ' src="/' ' src="/immich/';
sub_filter ' action="/' ' action="/immich/';
sub_filter 'import("/_app' 'import("/immich/_app';
sub_filter 'base: ""' 'base: "/immich"';
location /immich/_app/immutable/chunks {
sub_filter_types *;
sub_filter '"/api/socket.io"' '"/immich/api/socket.io"';
proxy_pass http://10.8.1.1:2283;
rewrite /immich/(.*) /$1 break;
}
location ~ /immich/_app/immutable/chunks/(index|app)\\. {
sub_filter_types *;
sub_filter '"/' '"/immich/';
proxy_pass http://10.8.1.1:2283;
rewrite /immich/(.*) /$1 break;
}
location ~ /immich/_app/immutable/chunks/constants {
sub_filter_types *;
sub_filter '="/' '="/immich/';
proxy_pass http://10.8.1.1:2283;
rewrite /immich/(.*) /$1 break;
}
location ~ /immich/_app/immutable/chunks/asset-utils {
sub_filter_types *;
sub_filter 'basePath:"/api"' 'basePath:"/immich/api"';
proxy_pass http://10.8.1.1:2283;
rewrite /immich/(.*) /$1 break;
}
location ~ /immich/_app/immutable/chunks/fetch-client\\. {
sub_filter_types *;
sub_filter 'baseUrl:"/api' 'baseUrl:"/immich/api';
proxy_pass http://10.8.1.1:2283;
rewrite /immich/(.*) /$1 break;
}
location ~ /immich/_app/immutable/chunks/api\\. {
proxy_pass http://10.8.1.1:2283;
rewrite /immich/(.*) /$1 break;
sub_filter_types *;
sub_filter '="/api"' '="/immich/api"';
sub_filter 'basePath:"/api"' 'basePath:"/immich/api"';
}
location ~ /immich/api/socket.io {
proxy_pass http://10.8.1.1:2283;
rewrite /immich/(.*) /$1 break;
proxy_cache off;
proxy_set_header Accept-Encoding $http_accept_encoding;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade websocket;
}
location ~ /immich/api {
proxy_pass http://10.8.1.1:2283;
rewrite /immich/(.*) /$1 break;
proxy_cache off;
sub_filter_types *;
sub_filter '"redirectUri":"/' '"redirectUri":"/immich/';
}
}
proxy_pass_request_headers on;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
slice 10m;
proxy_cache_key $uri$is_args$args$slice_range;
proxy_cache_lock on;
proxy_cache_lock_timeout 0s;
proxy_cache_lock_age 200s;
proxy_cache_min_uses 1;
proxy_set_header Range $slice_range;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_cache_use_stale error timeout invalid_header updating
http_500 http_502 http_503 http_504;
proxy_redirect off;
}
}
@picklescloud
Copy link

Hello,

Thank you very much for the configuration file; it has been extremely helpful!

However, after updating Immich to version v1.124.0 this morning, I encountered a significant issue. The update caused everything to break, and I received the following error:

Error: Error: 404
    at Object.ht [as ok] (https://mydomain.com/immich/_app/immutable/chunks/fetch-client.DqMPutSq.js:1:7918)
    at async Promise.all (index 0)
    at async n (https://mydomain.com/immich/_app/immutable/chunks/server-config.store.DzAD3Dok.js:1:530)
    at async o (https://mydomain.com/immich/_app/immutable/chunks/server.B9uUtD4f.js:1:224)
    at async ra (https://mydomain.com/immich/_app/immutable/nodes/0.CItVphcP.js:1:2484)
    at async Wt (https://mydomain.com/immich/_app/immutable/chunks/entry.CGh5KwEn.js:1:17711)

After some troubleshooting, I managed to create a configuration file that works for me. Additionally, I included support for large file uploads with the following directive:

client_max_body_size 50000M;

Here is my immich.conf

location /api/ {
    return 301 /immich$request_uri;
}

location /immich {
    proxy_pass http://127.0.0.1:2283;
    rewrite /immich/(.*) /$1 break;

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Accept-Encoding "gzip";
    
    gunzip on;
    proxy_pass_request_headers on;
    proxy_buffering on;
    proxy_cache_valid 200 206 1d;

    sub_filter_once off;
    sub_filter ' href="/' ' href="/immich/';
    sub_filter ' src="/' ' src="/immich/';
    sub_filter ' action="/' ' action="/immich/';
    sub_filter 'import("/_app' 'import("/immich/_app';
    sub_filter 'base: ""' 'base: "/immich"';
    sub_filter '"/api/' '"/immich/api/';

    # Handle the root path assets
    location /immich/ {
        proxy_pass http://127.0.0.1:2283/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # Handle JavaScript files
    location ~ \.js$ {
        sub_filter_types application/javascript;
        sub_filter '"/api/' '"/immich/api/';
        sub_filter_once off;

        proxy_pass http://127.0.0.1:2283;
        rewrite /immich/(.*) /$1 break;
    }

    location ~ /immich/_app/immutable/chunks/fetch-client\\. {
        sub_filter_types application/javascript;
        sub_filter 'baseUrl:"/api' 'baseUrl:"/immich/api';
        sub_filter '"/api/' '"/immich/api/';
        sub_filter_once off;

        proxy_pass http://127.0.0.1:2283;
        rewrite /immich/(.*) /$1 break;
    }

    # Handle WebSocket connections
    location ~ /immich/api/socket.io {
        proxy_pass http://127.0.0.1:2283;
        rewrite /immich/(.*) /$1 break;

        proxy_cache off;
        proxy_buffering off;

        proxy_set_header Accept-Encoding $http_accept_encoding;
        proxy_set_header Connection "upgrade";
        proxy_set_header Upgrade websocket;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # Handle API requests
    location ~ /immich/api {
        proxy_pass http://127.0.0.1:2283;
        rewrite /immich/(.*) /$1 break;

        proxy_cache off;
        proxy_buffering off;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        sub_filter_types *;
        sub_filter '"redirectUri":"/' '"redirectUri":"/immich/';
    }
}

I still have an issue on the administration panel where all links in the menu are rewritten with a second /immich, resulting in the following error:

Not found: /immich/immich/admin/library-management - 404
undefined

I can't figure out why this is happening. If anyone has any ideas, I would greatly appreciate your help !

Have a nice day !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment