簡體   English   中英

NGINX 和 nodeJs 適用於 http 但不適用於 https

[英]NGINX and nodeJs works with http but not https

我有 NGINX 的這個配置:

server {
  listen       80;
  listen       443 ssl;
  server_name  rahim27.fr;

  ssl_certificate  /etc/letsencrypt/live/rahim27.fr/cert.pem;
  ssl_certificate_key /etc/letsencrypt/live/rahim27.fr/privkey.pem;

  error_log logs/error.log warn;

  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;
  }
}

這個基本的 NodeJS 服務器:

const http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8080);

當我去http://rahim27.fr/時,我得到了我的hello world但如果我嘗試https://rahim27.fr/我得到ERR_CONNECTION_RESET ,使用 curl 它給了我curl: (7) Failed to connect to rahim27.fr port 443: No route to hostcurl: (35) schannel: failed to receive handshake, SSL/TLS connection failed

服務器位於雲虛擬機中,我在雲儀表板和虛擬機本身中打開了所有端口。

SSL 證書是由 certbot 自動生成的。

我想要的是 :

  1. https://rahim27.fr/返回一個hello world
  2. 在正確提供 http 和 https 之后,我還想將所有 http 流量重定向到 https

我嘗試了什么:

  1. 看stackoverflow
  2. 打開虛擬機上的所有端口(至少在我處於開發階段時)

最簡單的方法是刪除 ssl_certificate 和 ssl_certificate_key 行並使用負責自動管理 https 的 certbot。

我邀請您遵循以下易於遵循的說明:

https://certbot.eff.org

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM