Skip to content

Commit

Permalink
fix: add X-Accel-Buffering header on SSE response
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed May 20, 2023
1 parent 0728dd2 commit c59f758
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,10 @@ server{
proxy_set_header X-Forwarded-For $remote_addr;
proxy_cache_bypass $http_upgrade;
proxy_set_header Accept-Encoding gzip;
proxy_buffering off; # 重要:关闭代理缓冲
}
}
```

注意,为了 SSE 正常工作,需要关闭 Nginx 的代理缓冲。

之后使用 Let's Encrypt 的 certbot 配置 HTTPS:
```bash
# Ubuntu 安装 certbot:
Expand Down
1 change: 1 addition & 0 deletions middleware/sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ func SetSSEHeaders() func(c *gin.Context) {
c.Writer.Header().Set("Cache-Control", "no-cache")
c.Writer.Header().Set("Connection", "keep-alive")
c.Writer.Header().Set("Transfer-Encoding", "chunked")
c.Writer.Header().Set("X-Accel-Buffering", "no")
c.Next()
}
}

0 comments on commit c59f758

Please sign in to comment.