在 NGINX 上为节点 js 应用程序启用 HTTPS 不起作用
Enabling HTTPS on NGINX for a node js application is not working
我正在使用部署在 Ubuntu 服务器中的简单“hello world”Express.JS(8080 端口)应用程序,NGINX 反向代理设置如下。
应用程序适用于 http 端口但不适用于 https 端口
- nginx 版本:nginx/1.10.3 (Ubuntu)
- OpenSSL 1.0.2g 2016 年 3 月 1 日
而我的配置文件是这样的:
server {
listen 80;
listen 443 default ssl;
server_name localhost;
ssl_certificate /root/mydir/ssl/certificate.crt;
ssl_certificate_key /root/mydir/ssl/private.key;
location / {
proxy_pass http://localhost:8080;
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;
}
}
我的域 testdomain.com 的 http 连接配置工作正常,但 https://testdomain.com or https://www.testdomain.com
完全失败
这个配置出了什么问题?
SSL 证书由 sslforfree.com 生成。
server {
listen 80;
server_name example.com;
# force redirect http to https
rewrite ^ https://$http_host$request_uri? permanent;
}
server {
listen 443;
ssl on;
ssl_certificate /root/mydir/ssl/certificate.crt;
ssl_certificate_key /root/mydir/ssl/private.key;
server_name example.com;
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
....
}
我正在使用部署在 Ubuntu 服务器中的简单“hello world”Express.JS(8080 端口)应用程序,NGINX 反向代理设置如下。
应用程序适用于 http 端口但不适用于 https 端口
- nginx 版本:nginx/1.10.3 (Ubuntu)
- OpenSSL 1.0.2g 2016 年 3 月 1 日
而我的配置文件是这样的:
server {
listen 80;
listen 443 default ssl;
server_name localhost;
ssl_certificate /root/mydir/ssl/certificate.crt;
ssl_certificate_key /root/mydir/ssl/private.key;
location / {
proxy_pass http://localhost:8080;
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;
}
}
我的域 testdomain.com 的 http 连接配置工作正常,但 https://testdomain.com or https://www.testdomain.com
完全失败这个配置出了什么问题?
SSL 证书由 sslforfree.com 生成。
server {
listen 80;
server_name example.com;
# force redirect http to https
rewrite ^ https://$http_host$request_uri? permanent;
}
server {
listen 443;
ssl on;
ssl_certificate /root/mydir/ssl/certificate.crt;
ssl_certificate_key /root/mydir/ssl/private.key;
server_name example.com;
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
....
}