.net core nginx hosting sockets doesn't allow http post

后端 未结 3 1632
花落未央
花落未央 2021-01-23 01:17

I am trying to make a website that would have http functions including http post functions, and also web sockets (such as signalR). I am trying to host this website on an ubuntu

相关标签:
3条回答
  • 2021-01-23 01:35

    Here is my configuration for .Net Core API with nginx:

        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $http_connection;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
        proxy_set_header X-Forwarded-Proto $scheme;
    

    The main idea are remove these lines (if you have)

    proxy_set_header Connection "upgrade";
    proxy_set_header Connection keep-alive;
    

    and insert this line in your configuration

    proxy_set_header Connection $http_connection;
    

    Hope it helps.

    0 讨论(0)
  • 2021-01-23 01:43

    using $http_connection instead of keep-alive or upgrade

    proxy_set_header Connection $http_connection;
    
    0 讨论(0)
  • 2021-01-23 01:48

    This is not a fix to your question, but may be a workaround. I got around this by setting up 2 proxy locations in nginx to a single asp.net core kestrel site. One for the websockets with the

    proxy_cache_bypass $http_upgrade;
    

    and one for everything else. Looks like this. Top one is for all but websockets, bottom is for websockets. Note I have rewrites also.

    location /n/ {
            proxy_pass http://localhost:5001/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
    }
    
    location /nsock/ {
            proxy_pass http://localhost:5001/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
    }
    
    0 讨论(0)
提交回复
热议问题