Welcome! Log In Create A New Profile

Advanced

Reverse proxy for multiple apps using same route

Posted by grizzbouille 
Reverse proxy for multiple apps using same route
May 28, 2024 02:57PM
I am hosting two apps (a custom "Notes" app, and File browser) on my raspberry pi with nginx. I set a reverse proxy so I can access notes on localhost/notes and files on localhost/files. I can land on both app, but it seems that both frontend make requests to an api with route /api/..., and my login request on File Browser returns a 404. How can I ensure api requests are proxied to the correct "/api" backend ?

Here is my nginx config file at this point :

```
server {
listen 80;
listen 443;

# Notes
root /var/www;
index index.html;

location /notes {
root /var/www;
try_files $uri $uri/ /notes/index.html;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

# Notes API
location /api/ {
proxy_pass http://127.0.0.1:8000/;
}


# File browser
location /files/ {
proxy_pass http://localhost:8084/;
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_redirect off;

# Rewriting URLs for File Browser
rewrite ^/files/(.*)$ /$1 break;
}


location /static/ {
proxy_pass http://localhost:8084/static/;
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_redirect off;
}
}
```

Also, I added a proxy for File Browser static assets that works, but how should I do in case I host another apps that needs static assets on the same route ?
jmm
Re: Reverse proxy for multiple apps using same route
June 05, 2024 05:14PM
FileBrowser has a base URL setting at the application level. Set it to "/files", and then API endpoints should be at "/files/api/". Then, you no longer need the rewrite directive or the /static context.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 158
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready