Nginx 负载平衡中网站无法正确加载

Nginx 负载平衡中网站无法正确加载

我有 3 个这样的 Nginx 服务器 -

  • lab01.net => 192.168.89.128(负载均衡器)
  • lab02.net => 192.168.89.129 (后端)
  • lab03.net => 192.168.89.130(后端)

-------------- lab01.net 配置 ----------

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 配置 --------------------------

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 配置 -----------------------

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 和 HTTPS。

每个 lab02.net 和 lab03.net 服务器上都有 Selinux 策略“semanage fcontext -a -t httpd_sys_content_t "/srv/www(/.*)?”,而 lab01.net Nginx 负载均衡器上则有“setsebool -P httpd_can_network_connect”。

一切正常,问题是当我加载网站时,它们无法正确显示。字母、图像、内容等不在它们所属的位置。当我仅使用 index.html 进行测试时,一切都很好,但当我使用真正的 HTML 和 CSS 模板网站时,问题开始出现。

相关内容