I have a flask app (front end) that runs on port 5001 that calls a fast api application through various ajax requests, that sits on port 8000. Instead of having 127.0.0.1/api/...
hard-coded in the ajax request, I want it to be /api/...
and nginx to reverse proxy the 5001 port to 8000. I have tried numerous things in chat gpt and on here, but cannot work it out. I’m also on MacBook. The current implementation is this:
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:5001;
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;
}
location /api/ {
proxy_pass http://127.0.0.1:8000;
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;
}
}
I am pretty new to this and have tried adding the root and index into the location {} like this, but that hasn’t worked either.
location / {
root /templates/;
index index.html;
I should add that I am pretty new to this, but am tearing my hear out trying to get this to work!