Score:0

Websites do not loaded properly in Nginx loadbalancing

np flag

I have 3 Nginx Servers like this -

  • lab01.net => 192.168.89.128 (load balancer)
  • lab02.net => 192.168.89.129 (backend)
  • lab03.net => 192.168.89.130 (backend)

-------------- lab01.net configuration ----------

upstream backend {
        server  lab02.net:443;
        server  lab03.net:443;
}



server {
        listen  80;
        listen  [::]:80;

        server_name     lab01.net;
        return  301     https://lab01.net$request_uri;
}

server {
        listen  443 ssl http2;
        listen  [::]:443 ssl http2;
        server_name     lab01.net;

        ssl_certificate /etc/nginx/ssl/ssl.pem;
        ssl_certificate_key     /etc/nginx/ssl/ssl.key;

        location / {
                proxy_pass      https://backend;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        Host $host;
        }

}

------------------- lab02.net configuration --------------------------

server {
        listen  8080;
        listen  [::]:8080;

        server_name     lab02.net;
        return  301     https://lab02.net$request_uri;
}

server {
        listen  443 ssl http2;
        listen  [::]:443 ssl http2;
        server_name     lab02.net;

        root    /srv/www/en;
        index   index.html index.htm;

        ssl_certificate /etc/nginx/ssl/ssl.pem;
        ssl_certificate_key     /etc/nginx/ssl/ssl.key;

}

------------------- lab03.net configuration -----------------------

server {
        listen  8080;
        listen  [::]:8080;

        server_name     lab03.net;
        return  301     https://lab03.net$request_uri;
}

server {
        listen  443 ssl http2;
        listen  [::]:443 ssl http2;
        server_name     lab03.net;

        root    /srv/www/es;
        index   index.html index.htm;

        ssl_certificate /etc/nginx/ssl/ssl.pem;
        ssl_certificate_key     /etc/nginx/ssl/ssl.key;

}

Firewalld 8080, HTTP, and HTTPS are allowed on all servers.

Selinux Policy "semanage fcontext -a -t httpd_sys_content_t "/srv/www(/.*)?" is on each lab02.net and lab03.net servers and "setsebool -P httpd_can_network_connect" on lab01.net Nginx load balancer.

All works fine and the problem is that when I load the websites they do not appear correctly. The letters, images, content, etc... are not in a place where they belong to. When I use just only index.html to test it's just fine but when I use real HTML and CSS template website, the problem starts to appear.

Michael Hampton avatar
cz flag
Check your logs.
djdomi avatar
za flag
and the servername should match the domain name of the request not of each individual server
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.