Welcome! Log In Create A New Profile

Advanced

NginX Load Balancing with Podman Compose

Posted by jasi110 
NginX Load Balancing with Podman Compose
June 25, 2020 01:08PM
For those that may not know, podman is a container system that can run rootless. Podman-compose, Podman's version of docker-compose, requires that all ports be unique since they use a shared network. Si, I have several containers running services at different ports. I then configured nginx to have the services to be load balanced listed in the upstream block with their ports. I then have nginx listening at port 80. In the podman compose, I have the Nginx service listing at exposed port 8090.
When I run this scenario, if I go to http://localhost:8090, Nginx routes to port 80 for the upstream servers, but they are not available at port 80, so I get an HTTP 302 Found error. If I change that URL in the browser, from port 80 to 8090, that URL works. I cannot seem to find a way to tell Nginx that when it modifies the URL for the upstream servers, it should make them port 8090 externally, assuming that is what needs to be done.

This is my nginx.conf file:

worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';

log_format download '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$http_range" "$sent_http_content_range"';

client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;

client_header_buffer_size 1k;
large_client_header_buffers 4 4k;

gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;

output_buffers 1 32k;
postpone_output 1460;

sendfile on;
tcp_nopush on;

tcp_nodelay on;

keepalive_timeout 75 20;


upstream docker_nginx {
server solr1:8981;
server solr2:8982;
server solr3:8983;
}

server {
listen 80;

access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log debug;
rewrite_log on;

server_name localhost;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;

proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

location / {
proxy_pass http://docker_nginx;

}

location = /wpad.dat {
access_log off;
return 404;
}
}
}

Any help will be very much appreciated.

Thanks.
Re: NginX Load Balancing with Podman Compose
June 26, 2020 03:09PM
I found that even though I enter http://localhost:8090, NginX redirects to port 80, and port 80 is only valid inside the container, not on the host. If I change the redirected URL in the browser to include port 8090, the load balanced servers display fine. So, it seems NginX needs to know to redirect to port 8090 on the host. I've searched for how to accomplish this and I've had no luck. I've tried rewrite and proxy_redirect, but they both fail.
This is why I get the 302 and 502, because the URL is not valid on the host. How do I get the valid URL to be created on the host?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 70
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