How to start faye server on a rails app deployed using dokku? - ruby-on-rails

I've hosted my rails application on Digitalocean using Dokku. There's this need for my application to run real-time applications through Faye. I've been trying several ways like the shoreman plugin for Dokku and adding faye: bundle exec rackup faye.ru -s thin -E production to "Procfile" file. But no luck till now, need help on how I can get this Faye server running for my app.

You need to make several steps to have working faye server (e.g. on port 9292):
Your Procfile is OK
Expose port 9292 on Docker. I recommend install docker-options plugin and next dokku docker-options:add timer "-p 9292:9292"
Setup your app nginx.conf. Mine is here:
upstream app { server 127.0.0.1:49154; }
server {
listen [::]:80;
listen 80;
server_name app.dokku.mine;
location / {
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Request-Start $msec;
}
location /faye {
proxy_redirect off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_buffering off;
proxy_cache_bypass $http_pragma $http_authorization;
proxy_no_cache $http_pragma $http_authorization;
proxy_pass http://localhost:9292;
}
}
I suggest to install nginx-alt plugin because config is overwritten on every deploy.

Related

403 error occurs when starting restapi and websocket server using fastapi and nginx

I am trying to connect and use a server using websocket for fastapi with nginx.
403 error on server.
# server log
connection failed (403 Forbidden)
connection closed
I am using gunicorn, and I saw an article saying that some uvicorn should be used, and I changed it, but it did not work.
It works normally in the local environment.
What settings should I make to use rest-api and websocket together?
# nginx.conf
location /ws/ {
proxy_pass http://docker-fastapi;
proxy_redirect off;
proxy_buffering off;
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_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}

How do I use NGINX to route to multiple apps?

I have been messing around with NGINX (complete novice) and a home lab server. I have a few docker apps that I want to access via my domain. I have set up the https redirect and verified that it works. However my issue is getting the domain www.mydomain.net/app1 to resolve to app1 and www.mydomain.net/app2 to resolve to app2.
Here is my current config
server {
listen 443 ssl;
server_name mydomain.net www.mydomain.net;
*insert ssl configs*
location /tsd/ {
proxy_pass http://tsd:3334/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $http_host;
proxy_set_header x-Forwareded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
location /game/ {
proxy_pass http://game:5876/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $http_host;
proxy_set_header x-Forwareded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
I looked at the network tab headers after going to mydomain.net/tsd I see the request go in and then get a response header with location /printers/ instead of /tsd/printers/. I have tried a multitude of various things from stackoverflow and other sites to try and make the /tsd/ path stick.
Any help or suggestions would be greatly appreciated.
Thanks in advance.

Why signalR can't send message to the client when it run on the docker with nginx reverse proxy?

I can receive the message sent by the signalR hub when it run on the localhost, but when I put my program on the server which is using nginx reverse proxy, I can connect to the signalR hub but can't receive message from it. I don't know why? Is it the proplem of nginx.conf configuration file? Besides, I can see the website icon when I run it on localhost, but can't when it run on the linux server no matter whether using nginx reverse proxy.
I try to modify the nginx.conf file,I tried all of these command:
proxy_set_header Connection keep-alive;or:
proxy_set_header Connection "Upgrade";or:
proxy_set_header Connection $http_connection;
I don't know what the problem is.
server {
server_name www.website.com;
listen 80;
listen 443 ssl;
ssl_certificate 1_www.website.com_bundle.crt;
ssl_certificate_key 2_www.website.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://www.website.com:5050;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
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-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
I expect the signalR hub run on the server can send message to client, but now I can only make it when the program run on my localhost.
Thanks for help.
Frank

How to configure ngnix for rails port?

Hello this is my first time deploying rails app to a ubuntu server so after I configured nginx and got the "welcome to nginx page" at a certain IP ... and when I start rails application I must enter the port in the IP address for example 165.217.84.11:3000 in order to access rails so how to make rails run default when I run only this IP 165.217.84.11
You can set the redirection from the 80 port (wich is the default) to the 3000 like this:
worker_processes 1;
events { worker_connections 1024; }
http {
client_max_body_size 10m;
sendfile on;
upstream rails {
server 165.217.84.11:3000;
}
server {
listen 80;
location / {
proxy_pass http://rails-app;
proxy_redirect off;
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 $scheme;
proxy_set_header X-Forwarded-Ssl off;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
So, when you access 165.217.84.11 in the browser you should see your rails project.
In general you have to setup your nginx to use puma socket file and then it will access the website using socket file instead of using TCP port (:3000 by the default).
Here is a nice tutorial: link
And here is a short explanation why you should use sockets.

Configuring ActionCable with Elasticache for Rails 5.0 App on Elastic Beanstalk

I have created a Rails 5.0 app with Elastic Beanstalk on Amazon Web Services and I have been able to successfully create the website with a functioning database. The only problem is that I need ActionCable for my app to work and it is really hard for me to configure Elasticache and have the rails app successfully communicate to the Elasticache cluster.
A lot of people have told me that the load balancer in Elastic Beanstalk doesn't allow any communication to the the Elasticache cluster and I haven't been able to find any documentation on how to integrate Redis into Elastic Beanstalk in order to properly configure ActionCable.
Do you guys knows a step by step detailed approach to successfully set up ActionCable on Elastic Beanstalk Rails 5.0 app using Elasticache?
Most important thing is to change the loadbalancer to user TCP and SSL instead of HTTP and HTTPS. You also need to configure nginx to pass on the upgrade headers on the /cable location.
Try adding this file (nginx.config) in your .ebextensions folder:
files:
/etc/nginx/conf.d/proxy.conf:
content: |
client_max_body_size 500M;
server_names_hash_bucket_size 128;
upstream backend {
server unix:///var/run/puma/my_app.sock;
}
server {
listen 80;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server_name *.cmgresearch.net;
large_client_header_buffers 8 32k;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_buffers 8 32k;
proxy_buffer_size 64k;
proxy_pass http://backend;
proxy_redirect off;
location /assets {
root /var/app/current/public;
}
# enables WS support
location /cable {
proxy_pass http://backend;
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;
}
}
}
container_commands:
01restart_nginx:
command: "service nginx restart"
See https://blog.cmgresearch.com/2017/05/11/step-7-action-cable-on-elastic-beanstalk.html

Resources