I'm a newb, don't know much about nginx and how it interacts with frontend. I tried searching SO and Google, but I dont think I know the keywords to get good hits. This site is somewhat related, but couldn't solve my issue from it: basic setup. I have been looking for hours and nothing related to what I am inquiring about. What url string do I need to use in order for the front-end application (shinyR) can reach any of the (flask) back-end API servers? Prior to have 2 API servers, I would simply use the docker container name, like: pyapi:5000/post
for post request. Within my nginx.conf
file, I set up 2x api servers. So, how can it be load-balanced from the point of view of the front-end app? From host, I can type in localhost:1889
and it will round-robin select from my two API servers. But I want it to do the same from within the front-end app. Here is my nginx.conf
I took the example from example:
# declare flask app
upstream pyapi_app {
least_conn;
server pyapi1:5000;
server pyapi2:5000;
}
# declare shiny app
upstream shiny_app {
server shinyapp:3838;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# shinyapp server
server {
listen 80 default_server;
server_name shiny_app;
client_max_body_size 50M;
# normal requests go to shiny app
location / {
proxy_pass http://shiny_app;
proxy_redirect off;
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-Host $server_name;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 5d;
proxy_buffering off;
}
}
# python api server
server {
listen 81;
server_name pyapi_app;
# pyapi requests go to the flask app
location / {
proxy_pass http://pyapi_app;
proxy_redirect off;
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-Host $server_name;
}
}
question from:
https://stackoverflow.com/questions/65894105/what-url-hostname-to-use-in-front-end-app-downstream-from-nginx-proxy 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…