【问题标题】:Nginx Enable HTTPS/SSL when forwarding to other URLNginx 转发到其他 URL 时启用 HTTPS/SSL
【发布时间】:2015-01-22 07:46:36
【问题描述】:

目前,我正在使用 AWS Ubuntu EC2 实例,在端口 3000 上运行 Node.js 应用程序,该应用程序具有 Nginx 反向代理。我一直在尝试启用 HTTPS 并添加 SSL 证书,并且我已经成功,因为我在 nginx.conf 文件中没有收到任何错误。但是,我将我的主网站“example.com”重定向到 AWS 服务器的公共 DNS,当我尝试加载“http://example.com”或“https://example.com”页面时,我收到“无法连接”来自 Firefox 的错误,这是我的测试浏览器。此外,当我运行sudo nginx -t 时,配置文件中没有语法错误,当我检查/var/log/nginx/error.log 文件时,它是空的。下面是我当前的 nginx.conf 文件。

更新:我将 server_name 从 example.com 更改为我服务器的公共 DNS,我们称之为 amazonaws.com。现在,当我输入https://amazonaws.com 时,页面加载并在通过 ssllabs.com 运行网站时显示 SSL 证书。但是,当我输入 amazonaws.comhttp://amazonaws.com 时,我会像以前一样得到一个空白页。

user root;
worker_processes 1;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
  # max_clients = worker_processes * worker_connections / 4
  worker_connections 1024;
}

http {
  include mime.types;
  default_type application/octet-stream;
  sendfile on;

  gzip on;
  gzip_comp_level 6;
  gzip_vary on;
  gzip_min_length 1000;
  gzip_proxied any;
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  gzip_buffers 16 8k;

  # backend applications
  upstream nodes {
    server 127.0.0.1:3000;
    keepalive 64;
  }

  server {
    listen 80;
    return 301 https://$host$request_uri;
  }

  server {
    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/example_com.crt;
    ssl_certificate_key /etc/nginx/ssl/example_com.key;
    ssl_protocols SSLv3 TLSv1;
    ssl_ciphers HIGH:!aNULL:!MD5;
    server_name example.com;

    # everything else goes to backend node apps
    location / {
      proxy_pass http://nodes;

      proxy_redirect off;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Host $host;
      proxy_set_header X-NginX-Proxy true;
      proxy_set_header Connection "";
      proxy_http_version 1.1;
    }
  }
}

【问题讨论】:

    标签: ssl amazon-web-services nginx https amazon-ec2


    【解决方案1】:

    你应该给这个服务器定义

    server {
    listen 80;
    return 301 https://$host$request_uri;
    }
    

    还有一个 server_name(例如 amazonaws.com)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-19
      • 2018-03-06
      • 1970-01-01
      • 2023-03-10
      • 2021-09-24
      • 2018-02-19
      • 1970-01-01
      相关资源
      最近更新 更多