I am using a GET api in which there is a parameter which is dynamic(a variable). I want to get that variable and give it to my Django server, but how do I tackle this in Nginx as I have a static api location.
The code where I am hitting the api:
Here waterQuantity is variable that will be provided by the user.
http.Response response =await http.get('http://192.168.0.110/openValveConst/$waterQuantity');
This is my Nginx config file right now:
location /openValveConst/ {
# why should i add / at the end 5000/ to make it work
proxy_pass http://127.0.0.1:8000/openValveConst/?format=json
proxy_set_header X-Forwarded-For $remote_addr;
}
Please suggest changes that I should do to make this work.
2
Answers
You cannot do that in a monolithic server(at least not with flexibility), and even if you did somehow you might want to reload the config and restart nginx on-the-fly which is again a new headache of using pexpect or subprocess.
Though you can try micro container like docker, where you can efficiently change the configuration via YML/JSON/docker files.
Bottom line is you can have a flask project API (or django whichever you prefer) which get the config from the API(or even you can use cURL if it is not hard and fast to use python project as API caller) and once you get the updated config you update the docker file and put a new build with updated config, I would personally prefer to use micro-containers for such dynamic usage.
I am not sure, but since every request that begins with
openValveConst/
will be sent to your django application, you only need to specify a route in your django app that matches the query: