NGINX开源:确保平衡器和节点之间的通信加密

NGINX开源:确保平衡器和节点之间的通信加密

我正在设置一个必须使用 TLS 与其他节点通信的负载均衡器。这很重要,因为后端节点不在私有网络中。配置如下。

结果是 Nginx 返回502错误的网关,并且 Nginx 似乎无法重定向到我的域。此外,由于我使用开源版本,我不能使用解决上游配置中的关键字。如何更改此配置以让 Nginx 加密 example.com -> backendX.example.com 之间的数据?

注意:如果我在上游块中使用 IP 而不是 URL,负载平衡就会起作用,但我认为它没有加密

错误:

*3 upstream SSL certificate verify error: (2:unable to get issuer certificate) while SSL handshaking to upstream, client: 0.0.0.0, server: lb.example.com

的结果openssl s_client -connect backend1.example.com

Certificate chain
 0 s:CN = backend1.example.com
   i:C = US, O = Let's Encrypt, CN = R3
 1 s:C = US, O = Let's Encrypt, CN = R3
   i:C = US, O = Internet Security Research Group, CN = ISRG Root X1
 2 s:C = US, O = Internet Security Research Group, CN = ISRG Root X1
   i:O = Digital Signature Trust Co., CN = DST Root CA X3
upstream example.com{
   least_conn;
   server backend1.example.com;
   server backend2.example.com;
}

server {

        listen [::]:443 ssl ipv6only=on;
        listen 443 ssl;
        server_name lb.example.com;

        location / {
                proxy_pass https://example.com;

                proxy_ssl_trusted_certificate /etc/letsencrypt/.../chain.pem;
                proxy_ssl_session_reuse on;
                proxy_ssl_verify       on;
                proxy_ssl_verify_depth 2;
                proxy_set_header Host $host;
        }
    ssl_certificate /etc/letsencrypt/.../fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/.../privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

#### NGINX -T
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
    ##

    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;
    resolver 8.8.8.8 8.8.4.4 valid=30s;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # 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/*;
}

upstream example.com{
   least_conn;
   server backend1.example.com;
   server backend2.example.com;
}

server {

        listen [::]:443 ssl ipv6only=on;
        listen 443 ssl;
        server_name lb.example.com;

        location / {
                proxy_pass https://example.com;

                proxy_ssl_trusted_certificate /etc/letsencrypt/.../chain.pem;
                proxy_ssl_session_reuse on;
                proxy_ssl_verify       on;
                proxy_ssl_verify_depth 2;
                proxy_set_header Host $host;
        }
    ssl_certificate /etc/letsencrypt/.../fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/.../privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = lb.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80 default_server;
    listen [::]:80 default_server;

    server_name lb.example.com;
    return 404; # managed by Certbot


}

# configuration file /etc/letsencrypt/options-ssl-nginx.conf:
# This file contains important security parameters. If you modify this file
# manually, Certbot will be unable to automatically provide future security
# updates. Instead, Certbot will print and log an error message with a path to
# the up-to-date file that you will need to refer to when manually updating
# this file.

ssl_session_cache shared:le_nginx_SSL:10m;
ssl_session_timeout 1440m;
ssl_session_tickets off;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;

ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA";

nginx -t nginx:配置文件/etc/nginx/nginx.conf语法正常 nginx:配置文件/etc/nginx/nginx.conf测试成功

相关内容