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