nginx和blazor -上游过早关闭连接- 502坏网关

vnjpjtjt  于 2022-11-21  发布在  Nginx
关注(0)|答案(2)|浏览(181)

我试图在Nginx上部署一个blazor服务器模板应用程序,但我被这个问题卡住了。我尝试了所有我能在网上找到的东西,但仍然是同样的错误。
error.log *36从上游阅读响应标头时,上游过早关闭了连接,客户端:,服务器:,请求:“GET / HTTP/1.1”,上游:“http://127.0.0.1:7155/“
如果有帮助,浏览器只显示502代码
这是我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/*;
}

这里是位于/sites-enabled/的服务器块

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

我不知道我做错了什么,请帮帮我

kwvwclae

kwvwclae1#

基于this,我做了一些关于如何在Nginx上部署Blazor服务器应用程序的笔记。我分享并希望能有所帮助。
安装并启动nginx:

sudo apt-get install nginx
sudo service nginx start

现在您需要配置它,使到达端口80的请求传递到端口5000上的应用。为此,请在您喜欢的编辑器中打开/etc/nginx/sites-available/default文件。默认配置只定义一个服务器,侦听端口80。在此服务器下,查找以location /开头的部分:这是此服务器上根路径的配置。请将其替换为以下配置:

location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                # try_files $uri $uri/ =404;
                proxy_pass http://localhost:5000/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $host;
        }

这应该可以防止连接恢复到长轮询状态。

sudo nginx -s reload

/etc/nginx/sites-available/下的default如下所示:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                # try_files $uri $uri/ =404;
                proxy_pass http://localhost:5000/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                proxy_set_header Host $host;
        }

关于如何部署的Miscrosoft reference

0qx6xfy6

0qx6xfy62#

我刚刚解决了这个问题,服务器块被重定向到SSL,但当我调用上游我没有做https!
要解决我只是改变
代理传递http://dotnet;

代理服务器
现在一切都正常了。
我希望这能帮助更多的人,因为我失去了这么多的时间在这...

相关问题