【问题标题】:Enabling HTTPS on NGINX for a node js application is not working在 NGINX 上为节点 js 应用程序启用 HTTPS 不起作用
【发布时间】:2018-03-09 07:45:01
【问题描述】:

我正在使用部署在 Ubuntu Server 中的简单“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.comhttps://www.testdomain.com 完全失败

这个配置出了什么问题?

SSL 证书由 sslforfree.com 生成。

【问题讨论】:

    标签: node.js nginx https reverse-proxy


    【解决方案1】:
    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;
       ....
     }
    

    【讨论】:

    • 嗨,我仍然收到错误站点无法访问,现在即使 http 也无法正常工作请帮助
    • 要使 http 工作删除 # 强制将 http 重定向到 https 重写 ^ https://$http_host$request_uri?永恒的;日志在说什么?
    • nginx access.log 是空的,它没有移动 :-(
    • 感谢您的帮助,我的问题现在已经解决了,我没有注意到 443 端口已关闭。现在启用它的工作正常。
    猜你喜欢
    • 2020-10-31
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 1970-01-01
    相关资源
    最近更新 更多