2016-04-09 8 views
2

このばかげた問題を、WebSocket(Mosquitto MQTTサービス)をリバースプロキシとして設定するnginxを設定してください。 次設定がWSのために完璧に動作します://しかしWSSのために失敗://nginxリバースプロキシwss - クライアントがクライアント要求行を読み取っている間に無効なメソッドを送信しました

events { 
    worker_connections 768; 
} 

http { 
    sendfile on; 
    tcp_nopush on; 
    tcp_nodelay on; 
    keepalive_timeout 65; 
    types_hash_max_size 2048; 

    include /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log info; 

    gzip on; 
    gzip_vary on; 
    gzip_proxied any; 
    gzip_comp_level 6; 
    gzip_buffers 16 8k; 
    gzip_http_version 1.1; 
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 

    server { 
     listen 80; 
     listen 443 ssl; 

     # nginx is smart enough to ignore these when serving HTTP instead of HTTPS 
     ssl_certificate /etc/nginx/cert; 
     ssl_certificate_key /etc/nginx/key; 

     location /ws { 
      # access_log off; 

      rewrite ^/ws$/break; 
      rewrite ^/ws(.*)$ $1 break; 

      proxy_pass http://mqtt:9001; 
      proxy_redirect default; 
      proxy_set_header Host $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 https; 

      proxy_http_version 1.1; 
      proxy_set_header Upgrade $http_upgrade; 
      proxy_set_header Connection "Upgrade"; 
      proxy_read_timeout 86400; 
     } 

    } 

    client_max_body_size 1M; 
    client_body_buffer_size 1M; 
} 

ここで私はnginxのログに見るものです:

10.142.0.4 - - x03 \ x03 \ x03 \ x03 \ xFD \ xD4C \ x828 \ xDFai!\ xB1 \ x87 \ x01 \ x01 \ \ x00 \ x00 \ x9 \ xC0 \ x11 \ xC0 \ x07 \ xC0 \ xE1 \ x00 \ x0C \ xC0 \ x02 \ x00 \ x05 \ xC00 \ xC0、\ xC0(\ xC0 $ \ xC0 \ x14 \ xC0 "400 173" - "" - " 2016/04/09 1 9:15:17 [情報] 7#7:* 6クライアントがクライアント要求行を読み込み中に無効なメソッドを送信しました。クライアント:10.48.0.1、サーバー:、要求: "2.6OK 4f= 4 jЁǐ

私は完全に途方に暮れています - すべての非のWebSocketルート(左簡単にするために、元のスニペットのうち):(助けてくださいは、SSLで作業している、とTLSでのWebSocketの作品また、(

私が助けるならば、私はGCPのKubernetes内のDockerコンテナとしてNginxを実行しています。

答えて

6

私はこれで一日を無駄にするとは思えません。私のMQTT.JSクライアントでは、単にURLをwss://my.domain.com/wsからwss://my.domain.com:443/wsに変更していました。これをここに残しておくと、時間を節約できます。

関連する問題