所以我对SSL证书有一些问题。
我有一个反应应用程序运行在端口80。以及在端口443上运行的节点后端。
我有一个指向IP (xx.xx.xxx.xx)的域,它指向react应用程序。我使用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提出请求?
发布于 2019-06-11 11:55:54
您使用的标准端口80和443不同。这些端口是服务器的入口点,不建议用作在反向代理中运行的端口。
当使用反向代理时,我们将其他端口映射到端口80或端口443,以便可以分别通过HTTP或HTTPS公开访问这些端口。
如果我们想通过HTTPS访问所有东西,我们需要通过反向代理将react和节点应用程序映射到443,并将所有HTTP访问重定向到HTTPS。
因此,作为建议的步骤来修复:
1)使用不同的端口,例如3000用于react,3001用于节点。
2)配置侦听端口80的服务器块,以重定向到https (如return 301 https://<yourdomainhere.com> )
3)删除端口80服务器块中的ssl行。只在监听端口443的服务器块内使用它们。
4)修改upstream {}块,将端口3001用于节点应用程序。保留proxy_pass http://backend;的使用,这是很好的。
5)在监听端口443的服务器块中添加一个带有proxy_pass http://localhost:3000;的新位置块。现在您将有两个位置块,一个用于react,另一个用于节点。
6)使用server_name证书定义每个块的yourdomainhere.com,因为通常不允许颁发IP地址。我建议使用另一个服务器块使用HTTPS前缀将IP地址重定向到您的域。
7)检查错误,然后重新启动nginx。
https://stackoverflow.com/questions/56477164
复制相似问题