I have 2 APIs (one built with Flask and the other one with FastAPI):
-- home
-- app_flask
main_flask.py
-- app_fastapi
main_fastapy.py
I defined a get endpoint in both files:
main_flask.py
from flask import Flask
app = Flask(__name__)
@app.route("/hello_flask")
def hello():
return {"result": "Welcome to Flask"}
main_fastapi.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/hello_fastapi")
def hello():
return {"result": "Welcome to FastAPI"}
The first one runs on port 8000 and the second one on port 8001
This is my /etc/nginx/sites-enabled/default file:
server {
listen 80;
server_name {here_my_IP};
location /flask_app {
proxy_pass http://127.0.0.1:8000;
}
location /fastapi_app {
proxy_pass http://127.0.0.1:8001;
}
}
But once everything is running, when I access to
http://myIP/flask_app/hello_flask
or
http://myIP/fastapi_app/hello_fastapi
I get this error:
{"error":["404 - Resource Not Found"]}
I don't get this error if I use location / {} instead of location /app {} on the default Nginx file and then I access to
http://myIP/hello_fastapi (for example in the case of the first API)
So I conclude that I am incorrectly routing the apps on the defaul configuration Nginx file.
How should I do it?