Welcome! Log In Create A New Profile


Load balance HTTP requests to different API endpoints

Posted by cjansson 
Load balance HTTP requests to different API endpoints
August 30, 2018 04:23PM
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
Re: Load balance HTTP requests to different API endpoints
August 30, 2018 07:29PM
Upsteam specifies SERVERS not URL's.
For nginx specific pastes, you can use https://paste.ngx.cc/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 67
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready