我有一台运行反向代理服务器的 NGINX 服务器到 Node 应用程序。 现在我需要让它与 https 一起工作,但我不断收到 502: Bad Gateway error when trying to access the site at https
server {
listen 80;
server_name MYSERVERDOMAIN;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
server {
listen 443 ssl;
server_name MYSERVERDOMAIN;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
最佳答案
您的设置看起来是正确的,所以我不太确定这个问题。但是,我正在为我的生产服务器使用以下设置,并为 static assets
文件夹和 https
自动转发进行额外配置 - 这是您可能想要的最终设置 生产服务器
。希望对您有所帮助:
server {
listen 80;
server_name example.com;
rewrite ^/(.*) https://example.com/$1 permanent;
}
server {
server_name example.com;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate /etc/ssl/certs/www.example.chained.cer;
ssl_certificate_key /etc/ssl/private/www.example.com_ssl_private_key.key;
root /var/www/example/public;
location / {
try_files $uri @proxy;
}
location @proxy {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
关于javascript - NGINX 反向代理 Node HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45801044/