nginx 转发 websocket ws wss

DevOps Nginx评论8,516字数 1187阅读3分57秒阅读模式

转发ws

server {
    listen       80;
    server_name  localhost;
    error_log  /var/log/nginx/socket.error.log ;
    access_log /var/log/nginx/socket.access.log ;
        if ($request_uri ~ ^/proxy/(.*)){
                set $backend_host http://$1;
        }
                location ^~ /proxy/ {
                proxy_pass $backend_host;
                proxy_http_version 1.1;
                proxy_read_timeout 86400s;
                proxy_send_timeout 86400s;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                rewrite ^/proxy/(.*)$ /$1 break;
        }
}

转发wss

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}


server {
    listen 443 ssl http2;
    server_name  socket.lucky.com;    

    index index.html index.htm default.html default.htm;
    ssl_certificate /etc/nginx/ssl/8305759__lucky.com.pem;
    ssl_certificate_key /etc/nginx/ssl/8305759__lucky.com.key;
    error_log  /var/log/nginx/socket.error.log ;
    access_log /var/log/nginx/socket.access.log ;



        if ($request_uri ~ ^/proxy/(.*)){
                set $backend_host http://$1;
        }
                location ^~ /proxy/ {
                proxy_pass $backend_host;
                proxy_http_version 1.1;
                proxy_read_timeout 86400s;
                proxy_send_timeout 86400s;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
                rewrite ^/proxy/(.*)$ /$1 break;
        }




    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

继续阅读
DevOps
  • 本文由 发表于 2023年4月19日 15:04:12
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
  • websocket
Nginx禁止某个IP或者IP段访问的方法 Nginx

Nginx禁止某个IP或者IP段访问的方法

使用的是nginx进行转发 刚部署上线一天就发现被好多的恶意软件扫描了 于是我就把所有的ip给封了,只留下我自己的IP段可以访问 nginx配置访问ip需要修改nginx.conf文件,只需...
传统滚动发版 Nginx

传统滚动发版

nginx探活 server 192.168.4.20:9090 weight=1; server 192.168.3.20:9090 weight=1; check interval=2000...
新老域名跳转 Nginx

新老域名跳转

简述 新旧域名交替,想让老域名自动跳转到新的域名上。 新域名 [root@us-common-sre-adminwebproxy-1 conf.d]# cat kibana.zhen-inc.c...
评论  0  访客  0

发表评论