Using a proxy

Buffalo can be used raw to handle queries. You just need to start your app and listen on a given address and port:

# Env config
ADDR=0.0.0.0
PORT=80

# Start your app as a daemon, for example:
./myapp &

On common scenarios though, you'll be using a proxy to distribute queries to a cluster, handle cases when your app is down, and so on.

NGINX

NGINX allows two ways to be configured with your app:

Using an IP address

Single backend app on same host

app env config:

ADDR=127.0.0.1
PORT=3000

NGINX config:

upstream buffalo_app {
    server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://buffalo_app;
    }
}

Multiple backend apps

Using different ports just for the example:

app1 env config:

ADDR=0.0.0.0 
PORT=3000

app2 env config:

ADDR=0.0.0.0 
PORT=3001

app3 env config:

ADDR=0.0.0.0 
PORT=3002

NGINX config:

upstream buffalo_app_hosts {
    server host1.example.com:3000;
    server host2.example.com:3001;
    server host3.example.com:3002;
}

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://buffalo_app_hosts;
    }
}

Using an UNIX domain socket

since v0.10.3

UNIX sockets are a common way to do inter-process communication (IPC) on UNIX systems. This means a program A can talk to a program B, using a file descriptor, just like they do using the TCP stack.

In our case, this allows you to have an instance of Buffalo running behind the proxy, without having to handle the full TCP stack between Buffalo and the proxy. This way, your app will answer faster!

app env config:

ADDR=unix:/tmp/buffalo.sock

NGINX config:

upstream buffalo_app {
    server server unix:/tmp/buffalo.sock;
}

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://buffalo_app;
    }
}

Apache 2

Using an IP address

app env config:

ADDR=127.0.0.1
PORT=3000

Apache 2 config:

<VirtualHost *:80>
    ProxyPreserveHost On

    # Proxy requests to Buffalo
    ProxyPass / http://0.0.0.0:3000/
    ProxyPassReverse / http://0.0.0.0:3000/

    ServerName example.com
</VirtualHost>

Copyright © 2018 Buffalo. All rights reserved.

Buffalo Gopher designed by Ashley McNamara — Original Gopher designed by Renee French.