nginx將ws類型的websocket代理為wss類型的websocket


一、如果websocket的原始訪問地址為ws://test.com:8088/test/websocket,則進行如下的nginx的server部分配置

server {
listen 8086 ssl;
server_name localhost;

  ssl_certificate      /home/server/ssl/full_chain.pem;
  ssl_certificate_key  /home/server/ssl/private.key;

  ssl_session_cache    shared:SSL:1m;
  ssl_session_timeout  5m;

  ssl_ciphers  HIGH:!aNULL:!MD5;
  ssl_prefer_server_ciphers  on;

  location / {
      root   html;
      index  index.html index.htm;
  }

  location ~ ^/test/(.+)$ {
      proxy_pass http://127.0.0.1:8088/test/$1?$args;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
  }

}

二、配置后的websocket地址為wss://test.com:8086/test/websocket


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM