簡體   English   中英

Websockets與Nginx和ssl握手

[英]Websockets with Nginx and ssl handshake

我有用Rails和Ember前端編寫的應用程序。 Nginx服務器可以訪問它。 這是Rails部分的配置:

upstream app_project_app {
  server unix:///tmp/project.sock fail_timeout=0;
}

這是灰燼部分的配置:

server {
  listen 80;
  server_name project.demo.domain.pl;
  root /home/lunar/apps/project-ember/current;
  try_files /system/maintenance.html $uri/index.html $uri.html $uri @app;
  access_log /var/log/nginx/project_app_access.log;
  error_log /var/log/nginx/project_app_error.log;

  keepalive_timeout 5;
  proxy_read_timeout 60;
  proxy_send_timeout 60;
  proxy_connect_timeout 60;

  if ($request_method !~ ^(GET|HEAD|PUT|POST|DELETE|OPTIONS)$ ){
    return 405;
  }

  location ~ ^/assets/ {
    expires max;
    add_header Cache-Control public;

    add_header ETag "";
    break;
  }

  location = /favicon.ico {
    expires    max;
    add_header Cache-Control public;
  }


  location / {
    try_files $uri/index.html $uri.html $uri @app;
    error_page 404              /404.html;
    error_page 422              /422.html;
    error_page 500 502 503 504  /500.html;
    error_page 403              /403.html;
  }

  location @app {
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass http://app_project_app;
  }
}

現在,該應用程序已增長,並具有websockets服務器(使用faye)。 客戶端無法連接到服務器:

WebSocket connection to 'ws://project.demo.domain.pl/faye' failed: Error during WebSocket handshake: Unexpected response code: 400

我讀過,我需要為此握手啟用SSL。 如何在Nginx中做到這一點? 我還讀到,我不需要使用https,而只能將SSL用於websocket,是真的嗎? 如果是的話,在這種情況下應該如何看待nginx的配置?

為了獲得websocket支持,您需要在@app位置塊中添加以下指令

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade”;

在這里閱讀更多

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM