Ruby-on-rails – Apache Reverse Proxy Unix Socket

apachePROXYruby-on-railssocketsunix

I am trying to setup ProxyPass in Apache 2.4.7 using unix sockets to a puma server for a rails application. I keep receiving a 500 Internal Error. When I check the apache logs I receive this message:

No protocol handler was valid for the URL /. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

This is my proxy config in apache

ProxyPass / unix:///home/rails/rp/tmp/sockets/puma.sock|http://127.0.0.1/
ProxyPassReverse / unix:///home/rails/rp/tmp/sockets/puma.sock|http://127.0.0.1/

If I setup a Proxy Pass on a regular tcp port like this, it works fine.

ProxyPass / http://127.0.0.1:9292
ProxyPassReverse / http://127.0.0.1:9292

Any help is appreciated, let me know if you need anymore information.

Best Answer

In general, there is some point for checking for reverse proxy an http server app over unix socket:

  • Check if Apache already loaded required modules (proxy & http_proxy) using apachectl -M command
  • Make sure that socket path is accessible for www-data user (it is default apache user)
  • Check correctness of running app on unix socket using following command:
    curl --unix-socket /var/www/app/socket/path -XGET http:/someMethod
  • Check that ProxyPreserveHost On already present in your virtual host file and set socket address correctly (as unix:/var/www/path/to/your/socket) and after pipe mark path correctly (as |http://127.0.0.1/what/ever)
  • Make sure both ProxyPassReverse and ProxyPass is set correctly
Related Topic