zoukankan      html  css  js  c++  java
  • NGINX代理websocket配置

      如题,我在100.100.6.22的8100端口启动了一个web项目,通过/live/提供http接口,通过/live/ws/提供websocket接口,进入到nginx所在目录,修改nginx.conf文件:

    [sbt@wlf nginx]$ cd /usr/local/nginx
    [sbt@wlf nginx]$ vi conf/nginx.conf

      主要新增两个location:

    server {
        listen       7777;
        server_name  100.100.6.22;
        charset utf-8;
        access_log  logs/nacos.access.log  main;
        error_log   logs/nacos.error.log notice;
        index index.html; 
    
        location /live/ {
          proxy_pass http://100.100.6.22:8100/;
          proxy_set_header Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto  $scheme;
        }
    
    
        location /live/ws/ {
          proxy_pass http://100.100.6.22:8100/ws/;
          proxy_set_header Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_http_version  1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
        }
    }

      保存后重启nginx,使用root权限或者切换回root用户重启:

    [sbt@wlf nginx]$ sudo ./sbin/nginx -s reload

      跑一次websocket接口,可以看nginx日志:

    [sbt@wlf nginx]$ tail -f logs/access.log     
    { "@timestamp": "2020-11-24T13:43:11+08:00", "remote_addr": "10.110.1.66","costime": "8.183","realtime": "8.183","status": 101,"x_forwarded": "","referer": "","request": "GET /live/ws/meetingConnect?lang=cn&codec=raw&appid=123456 HTTP/1.1","upstr_addr": "100.100.6.22:8100","bytes":4695,"dm":,"agent": "" }
  • 相关阅读:
    win8.1下安装双系统ubuntu14.04.3
    如何使用cmd
    My Test about Mat
    访问Mat矩阵中的元素并为其赋值
    Mat代码操作
    waitKey()
    ASCII码对照表
    vector 中的clear()
    vector 介绍
    Mat的详解
  • 原文地址:https://www.cnblogs.com/wuxun1997/p/14031225.html
Copyright © 2011-2022 走看看