SSL nginx

Enable public web browsing

vi config/dev.exs
# http: [ip: {0, 0, 0, 0}, port: 4000],
http://phoenix.boffin.app

Setting up ssl in development

Two options:

  1. pure phoenix using non port 443
  2. phoenix on port 4001 and nginx 443 https://hexdocs.pm/phoenix/using_ssl.html
mix phx.gen.cert
# This will create certs in priv/cert/
vi config/dev.exs
# This failed.  Can't get remote FireFox to accept certificate

Using lets encrypt

https://certbot.eff.org/instructions?ws=other&os=debiantesting

# install snap
sudo apt install snapd

# install certbot
sudo snap install --classic certbot

# prepare certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

sudo certbot certonly --standalone

Make sure certs are are readable

sudo chown 755 ...pem

Configure phoenix certificate

This works for using non 443 port. For using port 443 use http instead of https and install nginx

vi config/dev.exs
# in config :hello, HelloWeb.Endpoint
url: [host: "phoenix.boffin.app"],
https: [
  port: 4001,
  cipher_suite: :strong,
  certfile:    "/etc/letsencrypt/live/phoenix.boffin.app/cert.pem",
  keyfile:     "/etc/letsencrypt/live/phoenix.boffin.app/privkey.pem",
  cacertfile:  "/etc/letsencrypt/live/phoenix.boffin.app/chain.pem"
]

Install git

sudo apt install git

cd hello
git init
git add *
git commit -m "first commit"

Set up for deployment

mix phx.gen.secret
iSz...oi0

export SECRET_KEY_BASE=iSz...oi0
export DATABASE_URL=ecto://elixirdbuser:elixirdbpass@fields/hello_dev

mix deps.get --only prod
MIX_ENV=prod mix compile

MIX_ENV=prod mix assets.deploy
PORT=4001 MIX_ENV=prod mix phx.server
# or for detached mode
PORT=4001 MIX_ENV=prod elixir --erl "-detached" -S mix phx.server

Install nginx

sudo apt update
sudo apt install nginx
sudo nginx -v

Run nginx

Reference: https://medium.com/@a4word/setting-up-phoenix-elixir-with-nginx-and-letsencrypt-ada9398a9b2c

systemctl status nginx
cat /etc/nginx/nginx.conf
### fill out nginx.conf
sudo systemctl enable nginx
sudo systemctl start nginx