0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

本番環境でFailed to upgrade to WebSocketエラー

Last updated at Posted at 2022-09-25

状況

ローカルでは投稿に対してのコメントができる(ajax)のに、本番環境ではできていなかった。

原因

本番環境でactioncableが使えない状況だった

解決方法

EC2内
$ sudo vim /etc/nginx/conf.d/rails.conf

以下を貼り付ける。

/etc/nginx/conf.d/rails.conf
upstream app_server {
  server unix:/var/www/アプリケーション名/shared/tmp/sockets/unicorn.sock;
}

server {
  #省略
# -------------------ここから-------------------
# /cableのパスに対してwebsocketの仕組みを用いるための設定
  location /cable {
    proxy_pass http://app_server/cable;
    proxy_http_version 1.1;
    proxy_set_header Upgrade websocket;
    proxy_set_header Connection Upgrade;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
# -------------------ここまでを追記-------------------
  #省略
}

これで、自分はコメント(ajax)ができるようになりました。

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?