Forum Discussion

standby's avatar
standby
Icon for Nimbostratus rankNimbostratus
Nov 13, 2022
Solved

Help with upstream prematurely closed!

Hello everyone!

I'm trying to publish a blazor server app (just a template app for testing) on Nginx in debian 11. Actually i have like a week stucked with this problem, reading every post writted about this error, but nothing works for me.

Someone can give me some light about what can be the problem?

Nginx conf:

 

 

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

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

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##
        gzip on;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

 

 

 server blocks at sites-enabled/test

 

 

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

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ssl_certificate /etc/nginx/cert.pem;
    ssl_certificate_key /etc/nginx/cert.key;

    location / {
        proxy_pass http://dotnet;
        proxy_set_header Host $host;
        proxy_http_version 1.1;  # you need to set this in order to use params below.
        proxy_temp_file_write_size 64k;
        proxy_connect_timeout 10080s;
        proxy_send_timeout 10080;
        proxy_read_timeout 10080;
        proxy_buffer_size 64k;
        proxy_buffers 16 32k;
        proxy_busy_buffers_size 64k;
        proxy_redirect off;
        proxy_request_buffering off;
        proxy_buffering off;
    }
}

upstream dotnet {
    zone dotnet 64k;
    server 127.0.0.1:7155;
}

 

 

 

  • I just solved the problem, the server block was redirecting to ssl, but when i call the upstream i was not doing with https!

    To solve i just change 

            proxy_pass http://dotnet;

     to 

            proxy_pass https://dotnet;

    and now everything works fine. 

    I hope this could help more ppl because i lost so much time in this...

3 Replies

  • I just solved the problem, the server block was redirecting to ssl, but when i call the upstream i was not doing with https!

    To solve i just change 

            proxy_pass http://dotnet;

     to 

            proxy_pass https://dotnet;

    and now everything works fine. 

    I hope this could help more ppl because i lost so much time in this...

  • Hi standby,

    your NIGNX config appears to be valid syntax. What error message to you get?
    Do the ssl_certificate and ssl_certificate_key exist in the location you specified?

     

    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
    
        ssl_certificate /etc/nginx/cert.pem;
        ssl_certificate_key /etc/nginx/cert.key;

    What outpout do you get when you run?

    nginx -t

    Did you try to run tcpdump on the server to check who is closing the connection? NGINX? Or your upstream server?

    KR
    Daniel