在 Linux 上“启用 TLS”通常指 让 OpenSSL 支持并使用 TLS 协议,而不是单独“开启”某个开关。下面按常见使用场景说明,你可以直接跳到你需要的部分。
openssl version -a
查看输出中是否包含:
OpenSSL 1.1.1 ✅(支持 TLS 1.3)OpenSSL 3.x ✅(支持 TLS 1.3)如果版本太老(如 1.0.2),TLS 1.3 不可用,只能支持到 TLS 1.2。
openssl s_client -connect example.com:443 -tls1_2
或 TLS 1.3:
openssl s_client -connect example.com:443 -tls1_3
查看协商的协议:
openssl s_client -connect example.com:443 | grep Protocol
openssl genrsa -out server.key 2048
openssl req -new -x509 -key server.key -out server.crt -days 365
openssl s_server \
-cert server.crt \
-key server.key \
-accept 4433 \
-tls1_2
客户端连接:
openssl s_client -connect 127.0.0.1:4433
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
}
重启:
systemctl restart nginx
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/server.crt
SSLCertificateKeyFile /etc/httpd/ssl/server.key
</VirtualHost>
SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
import ssl
import socket
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.load_verify_locations("/etc/ssl/certs/ca-certificates.crt")
with socket.create_connection(("example.com", 443)) as sock:
with context.wrap_socket(sock, server_hostname="example.com") as ssock:
print(ssock.version())
原因通常是:
✅ 解决:使用受信任 CA 证书 + TLS 1.2+
Linux 上 OpenSSL 默认就支持 TLS,只需在应用(Nginx / Apache / 程序)中明确配置证书并指定 TLS 版本即可。
如果你能告诉我:
我可以给你精确到配置文件的示例。