-
Notifications
You must be signed in to change notification settings - Fork 43
Drab in production and behind a proxy
When using in production, an app is often behind an apache/nginx server for domain virtualization or balancing, so the external port (80) is different from the actual app port (i.e. 4000). The necessary mapping between the two ports is usually done by configuring a proxy, but a particularly care have to be taken to correctly handle websocket
calls, as they are at the core of Drab mechanism to communicate between the client browser and the backend server.
Here there are some configuration examples for nginx and apache:
location / {
include proxy.conf;
proxy_http_version 1.1;
proxy_redirect off;
proxy_pass http://drab;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Cluster-Client-Ip $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
- Load the ws tunnel module adding this directive in
/etc/httpd/conf/httpd.conf
:
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
- set up a proxy for both
http
(and/or https) andws
adding the following directives inside thevirtualhost
block for your domain in the/etc/httpd/conf/httpd.conf
file:
ProxyPass /socket/ ws://example.com:4000/socket/
ProxyPassReverse /socket/ ws://example.com:4000/socket/
ProxyPass / http://example.com:4000/
ProxyPassReverse / http://example.com:4000/
- being sure to write the directives in the correct order:
The configured ProxyPass and ProxyPassMatch rules are checked in the order of configuration. The first rule that matches wins. So usually you should sort conflicting ProxyPass rules starting with the longest URLs first.
- restart apache:
# apachectl restart
Phoenix checks the origin of request when the origin header is present. It is compared against the host
value in YourApp.Endpoint.config(:url)[:host]
, so please ensure that the correct host is set in prod.exs
:
config :your_app, url: [host: "myhost.com", port: 443]