【发布时间】:2019-10-21 22:45:44
【问题描述】:
所以我在使用 SSL 证书时遇到了一些问题。
我有一个在端口 80 上运行的 react 应用程序。 以及在端口 443 上运行的节点后端。
我有一个指向指向反应应用程序的 IP (xx.xx.xxx.xx) 的域。我正在使用 nginx 代理从前端到后端的请求,因为我在同一台服务器上都有。
这里是 nginx 配置:
server {
listen 80 ssl;
server_name xx.xx.xxx.xx;
ssl_client_certificate /etc/letsencrypt/live/domain.com/cert.pem;
ssl_certificate /etc/letsencrypt/live/domain.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
root /home/ubuntu/build;
index index.html;
access_log /var/log/nginx/build.access.log;
error_log /var/log/nginx/build.error.log;
location / {
try_files $uri /index.html =404;
}
}
upstream backend {
server 127.0.0.1:443;
server 127.0.0.1:443 max_fails=1 fail_timeout=30s backup;
keepalive 64;
}
server {
listen 443 ssl;
server_name xx.xx.xxx.xx;
ssl_client_certificate /etc/letsencrypt/live/domain.com/cert.pem;
ssl_certificate /etc/letsencrypt/live/domain.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
keepalive_timeout 10;
location / {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_next_upstream error timeout http_500 http_502 http_503 http_504;
proxy_set_header Connection '';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
当向后端发出请求时,我收到以下错误:
net::ERR_CERT_COMMON_NAME_INVALID
这是因为证书对“domain.com”有效,而不是后端正在运行的 IP(我知道您必须为证书使用完全合格的域)。
我的问题是我可以做些什么不同的事情(使用 nginx)来允许我的请求通过反向代理上的 https 发出?
【问题讨论】:
-
试试
proxy_pass httpS://backend;? -
已经尝试过@ThanhNguyenVan 但谢谢!
标签: ssl nginx reverse-proxy lets-encrypt nginx-reverse-proxy