我正在尝试在后端配置重新加密,以便 nginx 和上游应用程序之间的流量与用户和 nginx 之间的流量分开加密。出于测试示例的目的,我使用的是:https ://github.com/jlengstorf/tutorial-deploy-nodejs-ssl-digitalocean-app.git. 我已经阅读了很多线程,但我总是得到错误 502:错误网关。另外,我不确定它是多么偏执,甚至为此烦恼。一切都在一个主机上,但我将运行多个服务,我的理由是它们中的任何一个都可能存在漏洞,并且每个应用程序都可以通过不同的证书与 nginx 通信来减轻这种风险。为使示例简单,我只对 Everything 使用了一个键。显然,如果我真的这样做,我将为每个重新加密实例制作一个新证书。我是网络托管和考虑安全性的新手,所以如果我在上面说了任何令人毛骨悚然的话,请告诉我。
mydomain.conf
# HTTP — redirect all traffic to HTTPS
server {
listen 443 ssl;
server_name 127.0.0.1:5000;
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;
root /var/www/html;
index test_index.html;
return 301 https://$host$request_uri;
}
# HTTPS — proxy all requests to the Node app
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name mydomain.com;
root /var/www/html;
index test_index.html;
# Use the Let’s Encrypt certificates
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;
# Include the SSL configuration from cipherli.st
include snippets/ssl-params.conf;
location /app {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass https://localhost:5000/;
proxy_ssl_verify on;
proxy_ssl_trusted_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
proxy_ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
/var/nginx/error.log 中的相应错误:
2020/10/22 16:17:13 [error] 11311#11311: *1 SSL_do_handshake() failed
(SSL: error:1408F10B:SSL routines:ssl3_get_record:wrong version number
) while SSL handshaking to upstream, client: xx.xxx.xx.xx, server: the
3guys.com, request: "GET /app HTTP/1.1", upstream: "https://127.0.0.1:
5000/", host: "mydomain.com"
在 nginx 站点 conf 中包含的 ssl-params.conf 片段中,我设置为使用我知道的所有 TLS 版本:
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;