Local Chat Does Not Work in a Production Environment

Asked 2 years ago, Updated 2 years ago, 72 views

What do you want to do
I want to set up a chat app that doesn't work in the production environment
I want to identify the elements I need to improve

Run Environment
Rails 5.2.4.2
nginx1.12.2
unicorn 5.4.1
AmazonLinux2

error
Developer Tool Console

WebSocket connection to 'wss:// Domain/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

log/production.log

 Failed to upgrade to WebSocket (REQUEST_METHOD:GET, HTTP_CONNECTION:close, HTTP_UPGRADE:)

What I've tried now

in config/environments/production.rb

1. Enable config.action_cable.allowed_request_origin=['http://example.com', /http:\/\/example.*/] and set the domain

What would you like to know
What else do you need?

After searching for all the elements that might be necessary, I noticed the following three points, but it was difficult to choose because some of them were used and others were not.

·ELB setting for AWS (does not support WebSockets communication over HTTP/HTTPS?)
·Set cable in /etc/nginx/conf.d/*.conf
·Redis settings

I would appreciate it if you could let me know.Thank you for your cooperation.

javascript ruby-on-rails ruby nginx

2022-09-30 16:11

1 Answers

https://teratail.com/questions/231471

Based on the above content, I was able to solve myself.

"·Other than ""Enable domain in config/environments/production.rb file""

"

Added the following code to nginx***.conf

 location/cable{
            proxy_pass http:// Application 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;
}


2022-09-30 16:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.