Skip to content

Instantly share code, notes, and snippets.

@aveexy
Last active May 5, 2024 11:26
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;
}
}
@gardiol
Copy link

gardiol commented Feb 23, 2024

I am getting these errors after trying this config:

Error: 404 (500)
Stacktrace
ie@https://xxx.mydomain.org/immich/_app/immutable/chunks/fetch-client.VozrW5mA.js:1:2905
ce@https://xxx.mydomain.org/immich/_app/immutable/chunks/fetch-client.VozrW5mA.js:1:2829

It's a popup in the middle of immich page as soon as i load it.
(it's working fine in subdomain at the same time)

@aveexy
Copy link
Author

aveexy commented Feb 23, 2024

probably incompatibility with new immich version, have not updated yet, will look into it

@aveexy
Copy link
Author

aveexy commented Mar 2, 2024

now compatible with immich v1.97.0

@Volkor3-16
Copy link

Volkor3-16 commented Mar 12, 2024

broken again for v1.98 :(

ue@https://xxx/immich/_app/immutable/chunks/fetch-client.QHRKs229.js:1:2907
ie@https://xxx/immich/_app/immutable/chunks/fetch-client.QHRKs229.js:1:2831

@aveexy
Copy link
Author

aveexy commented Mar 12, 2024

can you provide more details? when does this error occur?

v1.98.2 works mostly fine for me. only thing that does not work is the websocket connection, upstream did something that prevents the connection, and it's pretty annoying to debug :(

@Volkor3-16
Copy link

can you provide more details? when does this error occur?

v1.98.2 works mostly fine for me. only thing that does not work is the websocket connection, upstream did something that prevents the connection, and it's pretty annoying to debug :(

lol sorry - I left it out since it's the exact same as aveexy, as soon as I load up the app

Strange though, I'm on 1.98.0 since that's the latest on docker and getting the error

@aveexy
Copy link
Author

aveexy commented Mar 13, 2024

i've just updated the gist. added some fixes for the websocket connection. nginx completely loses it as soon as encoding headers are present and drops the connection upgrade headers needed for websocket protocol switch.

it might be necessary to delete all the cached files in /var/cache/nginx/immich_revprox

@sidamos
Copy link

sidamos commented May 5, 2024

Does anyone have a config for Apache?
Edit: Never mind, switched to using a subdomain.

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