Quantcast
Viewing all articles
Browse latest Browse all 4759

Load balance HTTP requests to different API endpoints

I'm new to NGINX and am trying to load balance between different API endpoints. For example, if I have two API endpoints that return data to a GET request, I should be able to send a GET request to my NGINX server and see it alternate between the two APIs.

For simplicity's sake, I am only using one API endpoint for now. Once I can get this one working, then I'll add a second one. Here is my conf file:



user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
upstream apis {
server api.openweathermap.org/data/2.5/weather?q=Berlin&APPID={API KEY};
}
server {
listen 80;
location / {
proxy_pass http://apis;
}
}
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

Sorry about the indentation, my spaces aren't showing up

Viewing all articles
Browse latest Browse all 4759

Trending Articles