设置 HardCoded Content-Length 标头会导致套接字挂断 Nginx 服务器 ExpressJS 应用程序

Setting HardCoded Content-Length Header Causes Socket-Hangup Nginx Server ExpressJS App

提问人:Muhtar 提问时间:11/15/2023 更新时间:11/15/2023 访问量:17

问:

我已将我的服务器从 IIS 移动到 Linux Nginx 服务器。Content-Length 标头从另一个开发人员设置为 366,并加载在分布在全国各地的硬件上运行。IIS 服务器允许硬编码的 Content-Length 标头,尽管有效负载上没有内容。另一方面,linux nginx 服务器不允许这样做,请求最终以“错误:套接字挂起”结束。如何允许硬编码的内容长度来拯救其他开发人员收集所有设备并使用新代码重新启动?

nginx.conf 文件;

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    client_max_body_size 1000M;
    gzip on;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
    listen       80 default_server;
        listen       [::]:80 default_server;
        #listen       443 ssl default_server;
        #listen       [::]:443 ssl default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
           location = /50x.html {
        }
    }


server {

    server_name  xx.xx.com;
 
    access_log /var/log/nginx/xx.log;
    error_log  /var/log/nginx/xx.error.log;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:3000;
        #proxy_redirect off;
           proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_read_timeout 300;
        proxy_connect_timeout 300;
        proxy_send_timeout 300;


    }








    listen 443 ssl; # managed by Certbot
    #listen [::]:443 ssl;    
    ssl_certificate /etc/letsencrypt/live/xx.xx.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/xx.xx.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = xx.xx.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


   server_name  xx.xx.com;
    listen 80;
  
    return 404; # managed by Certbot


}}
表达 nginx 请求 nginx-reverse-proxy

评论


答: 暂无答案