gpt4 book ai didi

node.js - NodeJs + Nginx .. upstream 在从 m upstream 读取响应头时过早地关闭了连接

转载 作者:搜寻专家 更新时间:2023-10-31 23:31:15 25 4
gpt4 key购买 nike

我的网站在端口 80 (http) 上运行,我使用 nginx 没有任何问题。下面是我在 nginx 中使用的默认文件

server {
listen 80;
server_name www.example.com;
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;
}
}

现在我打算使用https和下载的Lets encrypt certs。目前我无法访问该网站。我收到以下错误。

*[error] 754#754:1 个上游在读取响应 header 时过早关闭连接m 上游,客户端:xxx.xx.xxx.xxx,服务器:example.com,请求:“GET/favicon.ico HTTP/2.0”,上游:“http://127.0.0.1:3000/favicon.ico", host: "www.exapmple.com", referrer: "https://www.example.com/ "

下面是我的nginx默认文件

# HTTP — redirect all traffic to HTTPS
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
return 301 https://$host$request_uri;
}

server {
listen 443 default_server ssl;
listen [::]:443 ssl http2;
server_name example.com www.example.com;

# certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;


# intermediate configuration. tweak to your needs.
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
ssl_prefer_server_ciphers on;

# HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security max-age=15768000;

# OCSP Stapling ---
# fetch OCSP records from URL in ssl_certificate and cache them
ssl_stapling on;
ssl_stapling_verify on;

resolver 8.8.8.8;

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

}

我的nodejs代码如下

var app = express();
var port = 3000;
var server = https.createServer(app).listen(port, function() {
console.log("Application connected on port " + port);
});

并且服务器在端口 3000 上运行。

提前致谢..J

最佳答案

此问题现已解决。问题出在 nodejs 代码上。

我把上面的代码改成了

var app = express();
var port = 3000;
var server = app.listen(port, function() {
console.log("Application connected on port " + port);
});

https.createserver 在内部调用 http.server() 并创建实例。所以通过删除它,错误得到解决。

感谢帮助!!

关于node.js - NodeJs + Nginx .. upstream 在从 m upstream 读取响应头时过早地关闭了连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46506423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com