nginx代理websoket

配置文件如下:

http {
    include       mime.types;
    default_type  application/octet-stream;

    # for websoket
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    log_format  main escape=json '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      '"$upstream_addr" "$request_time" "$upstream_response_time"';

    access_log  logs/access.log  main;

    server {
        listen 80 default;
        server_name abc.test.com;
        access_log      logs/access.log       main;
        error_log       logs/error.log;

        location / {
            proxy_pass      http://127.0.0.1:8080;
			
            # for websoket
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    }
}

 

关键项即文中红色字体for websoket项。

 

更多参考:https://www.nginx.com/blog/websocket-nginx/

 

 

上一篇 多进程-进程与线程的区别
下一篇 多线程-Thread对象的其他属性和方法

探索站点内容

搜索文章、标签、分类

站点性能

运行正常
实时心跳0 ms
页面加载
0
SQL 查询
0
服务端响应
0 ms
峰值内存
0 MB