Running Django on FreeBSD using Bastille, Nginx, Postgresql, and Gunicorn     

Enable pf

sysrc pf_enable=yes
sysrc gateway_enable=yes

Setup Bastille

pkg install bastille
sysrc gateway_enable=YES
Bastille config

Start pf

I like running ssh on a different port so edit /etc/pf.conf and add the port by surrounding "ssh" with brackets like so for port 1014: {ssh,1024}

Bootstrap

bastille bootstrap 14.3-RELEASE

Setup Bastille

bastille setup

NGINX

bastille create nginx 14.3-RELEASE 10.0.0.10
bastille sysrc nginx nginx_enable=YES
bastille pkg nginx install nginx
bastille rdr nginx tcp 80 80
bastille rdr nginx tcp 443 443
bastille restart nginx

Postgresql

bastille create postgresql 14.3-RELEASE 10.0.0.11
bastille sysrc postgresql postgresql_enable=YES
bastille pkg postgresql install postgresql17-server
bastille config postgresql set allow.sysvipc=1
bastille service postgresql postgresql initdb
bastille service postgresql postgresql start
bastille restart postgresql
  1. add md5 authentication in /var/db/postgres/data17/pg_hba.conf
  2. expand listen in /var/db/postgres/data17/postgresql.conf

django-dobblet

bastille create django-dobblet 14.3-RELEASE 10.0.0.12
bastille pkg django-dobblet install uwsgi-py311 git-tiny
bastille sysrc django-dobblet uwsgi_enable=YES
bastille sysrc django-dobblet uwsgi_emperor=YES

bastille sysrc django-dobblet sshd_enable=YES
bastille service django-dobblet sshd start

#mount git
bastille mount django-dobblet /home/mike/git/dobblet /usr/home/mike/git/dobblet nullfs ro 0 0

Create database user and database:

# Create user and database
bastille cmd postgresql 'su - postgres -c "psql -U postgres -d template1 -c \"CREATE DATABASE dobblet\""'

bastille cmd postgresql 'su - postgres -c "createuser -d -r -s myuser"'
bastille cmd postgresql 'su - postgres -c "createdb mydatabase"'`

Configure PostgreSQL for external access: