使用Nginx为websockets / Rails / Kubernetes /Minukube配置什么config.action_cable.url?
当在Rails进程(不仅仅是API )和独立电缆进程(cf 导游)前面运行本地Nginx进程时,websockets通过传递以下服务器端(例如"/config/application.rb",并在布局中设置了action_cable_meta_tag )运行得很好:
config.action_cable.url = 'ws://localhost:28080'我正在本地使用Minikube开发Kubernetes :我在Rails部署(RAILS_ENV=production)和电缆部署之前部署了Nginx,但是我无法使它工作。电缆服务是"ClusterIP“类型的内部服务,带有”端口“和"targetPort”。我试过几种变体。
有什么建议吗?
请注意,我在Minikube上使用了Nginx -> Rails + Cable,入口点是Nginx服务,它是LoadBalancer类型的外部服务,我在其中使用:
upstream rails {
server rails-svc:3000;
}
server {
listen 9000 default_server;
root /usr/share/nginx/html;
try_files $uri @rails;
add_header Cache-Control public;
add_header Last-Modified "";
add_header Etag "";
location @rails {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header Host $http_host;
proxy_pass_header Set-Cookie;
proxy_redirect off;
proxy_pass http://rails;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}为了允许任何来源,我还设置了:
config.action_cable.disable_request_forgery_protection = true发布于 2021-08-04 11:05:55
我有一个答案:在Minikube集群中,不要放置任何东西并禁用伪造保护,Rails将默认正确的值。当Nginx位于一个Rails吊舱和一个独立的ActionCable/websocket的前面( Rails映像是用bundle exec puma -p 28080 cable/config.ru启动的)时,如果我将暴露ActionCable容器的服务命名为“线缆-svc”,而Rails容器的名称为“Rails”,则需要:
CABLE_URI的配置127.0.0.1:some_port),请执行:# config.action_cable.url <-- comment this
config.action_cable.disable_request_forgery_protection=trueupstream rails {
server rails-svc:3000;
}
server {
[...root, location @rails {...}]
location /cable {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass "http://cable-svc:28080";
}
}检查日志,没有更多的WebSockets在Rails,电缆响应。
https://stackoverflow.com/questions/68623069
复制相似问题