有這個荒謬的問題設置nginx反向代理websocket(一個Mosquitto MQTT服務)。 下面的配置完全適用於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 - - [09/Apr/2016:19:15:16 +0000]「\ x16 \ x03 \ x01 \ x012 \ x01 \ x00 \ x01。\ x03 \ x03- \ xFD \ xD4C \ x828 \ xDFai!\ xB1 \ x87 \ x96l \ x8E \ xF6a \ X00 \ x059 \ XC4 \ xF1y:\ X89 \ XFF $ d^\的x87 \ xE5 \ X00 \ x00z \ XC0' \ x00g \ X00 \ x9C \ XC0 \ X11 \ XC0 \ X07 \ XC0 \ x0C \ xC0 \ x02 \ x00 \ x05 \ xC00 \ xC0,\ xC0(\ xC0 $ \ xC0 \ x14 \ xC0「400 173」 - 「」 - 「 2016/04/09 1 9:15:17 [7] 7#7:* 6客戶端在讀取客戶端請求行時發送無效方法,客戶端:10.48.0.1,服務器:,請求:「2. 6OK 4f= 4 jЁǐ
我在一個完整的損失 - 請幫助:(所有非websocket路由(爲簡單起見,原來的代碼片斷)正在使用SSL,並與TLS websocket作品以及:(
如果有幫助,我將Nginx作爲Kubernetes上的Docker容器在GCP上運行。