Reputation: 47
Can anyone either 1) tell me how to do it, or 2) point me to a resource on how to run/enable/use SSL with the Erlang Web framework? I can't find anything in any docs or online web searches, and it looks like the last post to their mailing list is a couple of years old.
Thanks.
Upvotes: 1
Views: 491
Reputation: 30995
The first step to enable SSL in your Erlang Web application is to configure the underlying web server. For example, if you're using Inets, you can use the file:
config/inets_https.conf:
An example Configuration File (using Apache like syntax) looks like:
ServerName erlangweb_https
ServerRoot docroot
DocumentRoot docroot
BindAddress 0.0.0.0
Modules e_mod_inets
Port 443
SocketType ssl
SSLCertificateFile my.cert
SSLCertificateKeyFile my.key
SSLVerifyClient 0
You can also configure it using "erlang" syntax:
[{inets, [...]}].
More information about Erlang Web Server Configuration Files at:
http://wiki.erlang-web.org/Eptic/ServerConfiguration
And, specifically, for Inets:
http://www.erlang.org/doc/man/httpd.html
Once you have that in place, you can redirect users to HTTPS in your application controller like follows (assuming the server is using default ports):
{redirect, "https://" ++ e_conf:host() ++ "/" ++ wpart:fget("__path")}.
If your server is not using default ports, the above redirection becomes:
{redirect, "https://" ++ e_conf:host() ++ ":" ++ e_conf:https_port()
++ "/" ++ wpart:fget("__path")}.
For more information about configuration parameters in Erlang Web:
http://wiki.erlang-web.org/ProjectConf
To reduce verbosity, you might want to have look to Erlang Web annotations. For example , you could write something like:
?BEFORE.
https(true, _Mod, _Fun, Args) ->
case wpart:fget("__https") of
false ->
Host = e_conf:host(),
Port = e_conf:https_port(),
Path = wpart:fget("__path"),
Redirect = "https://" ++ Host ++ ":" ++ Port ++ "/" ++ Path,
{skip, {redirect, Redirect}};
true ->
{proceed, Args}
end.
And then use it just before your controller functions to force HTTPS:
?HTTPS(true).
my_function(Args) ->
....
Upvotes: 2