尽管我设置了 TLS 1.2,但 NGINX 仍强制使用 TLS 1.3

尽管我设置了 TLS 1.2,但 NGINX 仍强制使用 TLS 1.3

在我的服务器上,Debian 11 bullseye 5.10.0-20-amd64

# nginx -V
nginx version: nginx/1.18.0
built with OpenSSL 1.1.1n  15 Mar 2022
TLS SNI support enabled

使用 mozilla 的 SSL 配置时(https://ssl-config.mozilla.org/#server=nginx&version=1.18.0&config=intermediate&openssl=1.1.1n&guideline=5.6), nginx 仅强制使用 TLS 1.3。我无法使用 TLS 1.2 连接到服务器。

* [CONN-0-0][CF-SSL] TLSv1.0 (OUT), TLS header, Certificate Status (22):
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS handshake, Client hello (1):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS header, Unknown (21):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS alert, protocol version (582):
* OpenSSL/3.0.7: error:0A00042E:SSL routines::tlsv1 alert protocol version
* Closing connection 0
curl: (35) OpenSSL/3.0.7: error:0A00042E:SSL routines::tlsv1 alert protocol version

我的服务器上有些客户端使用不支持 TLS 1.3 的服务。目前它们都无法连接。

有人知道为什么 f* nginx 只强制执行 TLS 1.3 吗?

nginx 配置中没有一行(通过 nginx -T 查看)只显示 TLS 1.3。我完全不知道如何修复此问题,因此非常感谢任何帮助或指导。

nginx.conf

user www-data;
worker_processes 4;
worker_rlimit_nofile 25000;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
load_module modules/ngx_http_modsecurity_module.so;

events {
        worker_connections 4096;
        # 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;

        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 error;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_vary on;
        gzip_min_length 10240;
        gzip_proxied expired no-cache no-store private auth;
        gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/sites-enabled/*.vhost;
}

默认虚拟主机

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

        server_name master.nerdvpn.de;

        location /.well-known/acme-challenge/ {
                allow all;
                default_type "text/plain";
                alias /var/www/acme/;
        }
}

server {
        listen 443 ssl http2 default_server;
        listen [::]:443 ssl http2 default_server;

        server_name master.nerdvpn.de;

        add_header X-Robots-Tag "none" always;

        ssl_certificate         /srv/letsencrypt/certs/master.nerdvpn.de/fullchain.pem;
        ssl_certificate_key     /srv/letsencrypt/certs/master.nerdvpn.de/privkey.pem;

        # https://ssl-config.mozilla.org/#server=nginx&version=1.18.0&config=intermediate&openssl=1.1.1n&guideline=5.6
        ssl_session_timeout 1d;
        ssl_session_cache shared:nginx_TLS_default:10m;  # about 40000 sessions
        ssl_session_tickets off;

        # curl https://ssl-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
        ssl_dhparam /srv/letsencrypt/dhparam.pem;

        # intermediate configuration
        ssl_protocols TLSv1.2 TLSv1.3;
        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;
        ssl_prefer_server_ciphers off;

        # HSTS (ngx_http_headers_module is required) (63072000 seconds)
        add_header Strict-Transport-Security "max-age=63072000" always;

        # OCSP stapling
        ssl_stapling on;
        ssl_stapling_verify on;

        # verify chain of trust of OCSP response using Root CA and Intermediate certs
        ssl_trusted_certificate /srv/letsencrypt/ocsp/BPClass2CA2Bundle.pem;

        access_log off;
        error_log /var/log/nginx/errors/server.log;

        location / {
                deny all;
        }
}

nextcloud.vhost

upstream php-handler {
        server unix:/var/run/php/php-fpm.sock;
}

limit_req_zone $binary_remote_addr zone=nextcloud_login:8m rate=60r/m;

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

                server_name nerdvpn.de www.nerdvpn.de;

                location ^~ /.well-known/acme-challenge/ {
                                allow all;
                                default_type "text/plain";
                                alias /var/www/acme/;
                }

                location / {
                                return 301 https://$server_name:443$request_uri;
                }
}


server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name nerdvpn.de www.nerdvpn.de;

        ssl_certificate /srv/letsencrypt/certs/nerdvpn.de/fullchain.pem;
        ssl_certificate_key /srv/letsencrypt/certs/nerdvpn.de/privkey.pem;
        
        # https://ssl-config.mozilla.org/#server=nginx&version=1.18.0&config=intermediate&openssl=1.1.1n&guideline=5.6
        ssl_session_timeout 1d;
        ssl_session_cache shared:nginx_TLS_nx:10m;  # about 40000 sessions
        ssl_session_tickets off;

        # curl https://ssl-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
        ssl_dhparam /srv/letsencrypt/dhparam.pem;

        # intermediate configuration
        ssl_protocols TLSv1.2 TLSv1.3;
        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;
        ssl_prefer_server_ciphers off;

        # HSTS (ngx_http_headers_module is required) (63072000 seconds)
        add_header Strict-Transport-Security "max-age=63072000" always;

        # OCSP stapling
        ssl_stapling on;
        ssl_stapling_verify on;

        # verify chain of trust of OCSP response using Root CA and Intermediate certs
        ssl_trusted_certificate /srv/letsencrypt/ocsp/BPClass2CA2Bundle.pem;

        access_log off;
        error_log /var/log/nginx/errors/nextcloud.log error;

        client_max_body_size 512M;
        fastcgi_buffers 64 4K;

        gzip on;
        gzip_vary on;
        gzip_comp_level 4;
        gzip_min_length 256;
        gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
        gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

        add_header Referrer-Policy "no-referrer" always;
        add_header X-Content-Type-Options "nosniff" always;
        add_header X-Download-Options "noopen" always;
        add_header X-Frame-Options "SAMEORIGIN" always;
        add_header X-Permitted-Cross-Domain-Policies "none" always;
        add_header X-Robots-Tag "none" always;
        add_header X-XSS-Protection "1; mode=block" always;

        fastcgi_hide_header X-Powered-By;

        root /srv/nextcloud;

        index index.php index.html /index.php$request_uri;

        # Microsoft DAV clients
        location = / {
                if ( $http_user_agent ~ ^DavClnt ) {
                        return 302 /remote.php/webdav/$is_args$args;
                }
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location ^~ /.well-known {
                # The rules in this block are an adaptation of the rules
                # in `.htaccess` that concern `/.well-known`.

                location = /.well-known/carddav { return 301 /remote.php/dav/; }
                location = /.well-known/caldav  { return 301 /remote.php/dav/; }

                location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
                location /.well-known/pki-validation    { try_files $uri $uri/ =404; }

                return 301 /index.php$request_uri;
        }

        # Hide certain paths from clients
        location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)  { return 404; }
        location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console)                                { return 404; }

        location ~ \.php(?:$|/) {
                rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;

                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                set $path_info $fastcgi_path_info;

                try_files $fastcgi_script_name =404;

                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $path_info;
                fastcgi_param HTTPS on;

                fastcgi_param modHeadersAvailable true;
                fastcgi_param front_controller_active true;
                fastcgi_pass php-handler;

                fastcgi_intercept_errors on;
                fastcgi_request_buffering off;

                fastcgi_max_temp_file_size 0;
        }

        location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
                try_files $uri /index.php$request_uri;
                expires 6M;              # Cache-Control policy borrowed from `.htaccess`
                access_log off;  # Optional: Don't log access to assets

                location ~ \.wasm$ {
                        default_type application/wasm;
                }
        }

        location ~ \.woff2?$ {
                try_files $uri /index.php$request_uri;
                expires 7d;              # Cache-Control policy borrowed from `.htaccess`
                access_log off;  # Optional: Don't log access to assets
        }

        location /remote {
                return 301 /remote.php$request_uri;
        }

        location /login {
                limit_req zone=nextcloud_login burst=12 delay=4;
                try_files $uri $uri/ /index.php$request_uri;
        }
        location / {
                try_files $uri $uri/ /index.php$request_uri;
        }
}

干杯!

答案1

我可以通过从源代码构建 nginx 来修复该问题。无需更改配置,它现在就可以正常工作。我不知道为什么,但 Debian 存储库中的默认 nginx 拒绝在我的计算机上使用 TLS 1.2。

* [CONN-0-0][CF-SSL] TLSv1.0 (OUT), TLS header, Certificate Status (22):
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS handshake, Client hello (1):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS header, Certificate Status (22):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS handshake, Server hello (2):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS header, Certificate Status (22):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS handshake, Certificate (11):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS header, Certificate Status (22):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS header, Certificate Status (22):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS handshake, Server finished (14):
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS header, Certificate Status (22):
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS header, Finished (20):
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS header, Certificate Status (22):
* [CONN-0-0][CF-SSL] TLSv1.2 (OUT), TLS handshake, Finished (20):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS header, Finished (20):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS header, Certificate Status (22):
* [CONN-0-0][CF-SSL] TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES256-GCM-SHA384

相关内容