小编Mac*_*jek的帖子

如何配置nginx代理ws(websocket)协议

我已成功将 Nginx 配置为我的 Web 应用程序的反向代理。它正确地将从我的 Angular SPA 发出的请求重定向到用 Asp Core 2.1 编写的 Web API。但是,在我的 Web API 中,我想使用ws://mydomain.com/ws用于建立连接的WebSockets 。

这就是我现在可用的网站的样子

server {
    listen 80;
    listen 443;
    ssl on;
    ssl_certificate /etc/***/***.crt;
    ssl_certificate_key /etc/***/***.key;

    root /home/***/***/***/wwwroot;

    # Add index.php to the list if you are using PHP
    index index.html;

    server_name my.domain.com;
    location / {
            try_files $uri $uri/ /index.html;
    }
    location /api/ {
            proxy_pass http://localhost:5000;
    }
    location /api/signalr {

            proxy_pass http://localhost:5000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $http_connection;
            proxy_set_header Host $host; …
Run Code Online (Sandbox Code Playgroud)

reverse-proxy nginx websocket

4
推荐指数
1
解决办法
8413
查看次数

标签 统计

nginx ×1

reverse-proxy ×1

websocket ×1