Skip to content

Instantly share code, notes, and snippets.

@thadeu
Last active August 9, 2023 17:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thadeu/a29aa8413385aa82fa7007ff51ca8296 to your computer and use it in GitHub Desktop.
Save thadeu/a29aa8413385aa82fa7007ff51ca8296 to your computer and use it in GitHub Desktop.
ActionCable WebSocket with Passenger + Apache2 + ProxyPass/ProxyPassReverse

Requirements:

  • httpd 2.4.5 and later
  • Enable Apache2 modules:
sudo a2enmod proxy proxy_ajp proxy_http rewrite deflate headers proxy_balancer proxy_connect proxy_html proxy_wstunnel
<VirtualHost *:80  *:443>
  ServerName api.mysite.com.br
  ServerAlias app.mysite.com.br

  DocumentRoot "/webapp/mysite/public"

  #SSLEngine On
  #SSLProxyEngine On

  ProxyRequests Off
  ProxyPreserveHost on

  <Location />
    ProxyPass http://0.0.0.0:3000/
    ProxyPassReverse http://0.0.0.0:3000/
  </Location>

  <Location /cable>
    ProxyPass ws://mysite.com.br:3000/cable
    ProxyPassReverse ws://mysite.com.br:3000/cable
  </Location>

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  <Directory "/webapp/mysite/public">
        Options FollowSymlinks Multiviews
        AllowOverride All
        Allow from all
        Require all granted
        RailsEnv production
  </Directory>

  #SSLCertificateFile /etc/letsencrypt/live/mysite.com.br/fullchain.pem
  #SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com.br/privkey.pem
  #Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Running Application

  • Restarting apache2
sudo services apache2 restart
  • Stoping app
passenger stop --port 3000
  • Starting app
passenger start --daemonize --address 0.0.0.0 --port 3000 -e production
@i-devers
Copy link

i-devers commented Jul 6, 2020

Thanks! you are the first person that documented this setup. Much appreciated the gist...
all the others were using passenger and Nginx, but needed the native apache to use with my puma...

@jasjeetsingh527
Copy link

Thank you, I was just thinking to move to NGINX because my action cable was not working but you helped me and it start's working :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment