[Optimization] Use nginx as reverse proxy in front of express #176

Closed
opened 2026-04-24 23:00:10 +02:00 by adam · 5 comments
Owner

Originally created by @JKamsker on GitHub (Jan 11, 2022).

Currently downloading is only half as fast as it would be possible.
This is annoying, especially when i want to download an audiobook directly to my phone.

This could be solved by using nginx as fileserver and proxying api requests to express.
In my tests nginx almost always gave me 900+mbit while express only gave me 400-600mbit

Authentication shouldnt be an issue, because the "attacker" would have to know the exact path to the files. Those are already semi-protected by random id path-strings

Implementation should be pretty straight forward, maybe even with the same url schemes. If schemes change, clients would probably break :/

Originally created by @JKamsker on GitHub (Jan 11, 2022). Currently downloading is only half as fast as it would be possible. This is annoying, especially when i want to download an audiobook directly to my phone. This could be solved by using nginx as fileserver and proxying api requests to express. In my tests nginx almost always gave me 900+mbit while express only gave me 400-600mbit Authentication shouldnt be an issue, because the "attacker" would have to know the exact path to the files. Those are already semi-protected by random id path-strings Implementation should be pretty straight forward, maybe even with the same url schemes. If schemes change, clients would probably break :/
adam closed this issue 2026-04-24 23:00:10 +02:00
Author
Owner

@mx03 commented on GitHub (Jan 11, 2022):

I don't think everyone does need a nginx and every docker should contain only one service, but a docker compose with a nginx that proxy the ui and override some paths for direct calls shouldn't be a problem.

For example:
nginx maps the folder AUDIOBOOKMETA/streams/ AUDIOBOOKMETA/downloads/ , the ui with a reverse proxy and override the route to /hls/ and /api/download/

(Not tested)

location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass         http://xxxx:13378;
    }
location /hls/ {
        root AUDIOBOOKMETA/streams;
    }
location /api/download/ {
        root AUDIOBOOKMETA/downloads;
    }
@mx03 commented on GitHub (Jan 11, 2022): I don't think everyone does need a nginx and every docker should contain only one service, but a docker compose with a nginx that proxy the ui and override some paths for direct calls shouldn't be a problem. For example: nginx maps the folder AUDIOBOOKMETA/streams/ AUDIOBOOKMETA/downloads/ , the ui with a reverse proxy and override the route to /hls/ and /api/download/ (Not tested) ``` location / { proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; proxy_pass http://xxxx:13378; } location /hls/ { root AUDIOBOOKMETA/streams; } location /api/download/ { root AUDIOBOOKMETA/downloads; } ```
Author
Owner

@JKamsker commented on GitHub (Jan 11, 2022):

Oh nice thanks!
I'll create a doc-pr explaining that for those who are interested as soon as i got it working :3

@JKamsker commented on GitHub (Jan 11, 2022): Oh nice thanks! I'll create a doc-pr explaining that for those who are interested as soon as i got it working :3
Author
Owner

@JKamsker commented on GitHub (Jan 11, 2022):

Thinking about that single service paradigm: nginx in front of the files and the api isnt exactly a separate service.

Its as much of a seperate service as ffmpeg or ffprobe which abs also needs to function.

@JKamsker commented on GitHub (Jan 11, 2022): Thinking about that single service paradigm: nginx in front of the files and the api isnt exactly a separate service. Its as much of a seperate service as ffmpeg or ffprobe which abs also needs to function.
Author
Owner

@mx03 commented on GitHub (Jan 11, 2022):

No, one docker container should use one service per container and use it as entry point.
That would be the nodejs app, the app manage the subprocesses (ffmpeg, ffprobe) itself.

If you have this only in intranet you don't need a nginx or better performance.
If you have a server with many different apps you probably already have a gateway service like nginx.
A single docker without additional packed with nginx is only a unnecessary overhead.
If you dont have a nginx in front you could just use a docker compose.

@mx03 commented on GitHub (Jan 11, 2022): No, one docker container should use one service per container and use it as entry point. That would be the nodejs app, the app manage the subprocesses (ffmpeg, ffprobe) itself. If you have this only in intranet you don't need a nginx or better performance. If you have a server with many different apps you probably already have a gateway service like nginx. A single docker without additional packed with nginx is only a unnecessary overhead. If you dont have a nginx in front you could just use a docker compose.
Author
Owner

@mx03 commented on GitHub (Jan 11, 2022):

Here is a working docker compose example:
https://gist.github.com/mx03/a83c1b274b833ad8ac25353bc892a57a
(the templates_default.conf.template must be in templates/default.conf.template)

There are also opensource jwt validation modules for nginx, that restrict the access if the passed jwt token is not valid.

@mx03 commented on GitHub (Jan 11, 2022): Here is a working docker compose example: https://gist.github.com/mx03/a83c1b274b833ad8ac25353bc892a57a (the templates_default.conf.template must be in templates/default.conf.template) There are also opensource jwt validation modules for nginx, that restrict the access if the passed jwt token is not valid.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#176