nginx配置websocket


# 配置在server同级
map $http_upgrade $connection_upgrade {
  default upgrade;
  ''   close;
}
server {
  listen                          80;
  server_name                     localhost;
  client_max_body_size            512M;
  keepalive_timeout               1800s;
  sendfile                        on;
  chunked_transfer_encoding       on;
  root                            /app/face_safe/dist;
  index                           index.html;

  location / {
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods *;
    add_header Access-Control-Allow-Headers *;
    try_files                     $uri $uri/ @req;
    index                         index.html;
  }

  location @req {
    rewrite ^.*$                  /index.html last;
  }

  location /v1 {
    proxy_set_header Access-Control-Allow-Origin *;
    proxy_set_header Access-Control-Allow-Methods *;
    proxy_set_header Access-Control-Allow-Headers *;
    proxy_set_header Upgrade $http_upgrade;  # websocket
    proxy_set_header Connection $connection_upgrade;  # websocket 
    proxy_pass                    http://172.17.0.1:8000;
  }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM