This role provides a jailed nginx server that listens on localhost:{80,443}
for incoming requests.
The role also provides a working SSL configuration using functionality provided by Let's Encrypt.
You need to provide a custom dhparam.pem
file. Create a folder named after
your server name (example.com
) within the folder files
next to your playbook.
The certificate will be validated/generated by periodic weekly
. In order to
get the server up and running immediately a self-signed localhost certificate
is installed. You may generate your Let's Encrypt certificates manually after
the jail has been started using the following command:
/usr/local/bin/acme-client-weekly.sh
It may be used by other roles to serve WordPress or Joomla installations. To access the webroot directory a SFTP server is also configured, which is secured by public key authentication.
This role may also be used to create SSL terminating proxy that forwards traffic to domain specific jails or external sites.
This role is intent to be used with a fresh FreeBSD installation. There is a Vagrant Box with providers for VirtualBox and EC2 you may use.
Set to yes
the enabled automatic certificate management with Lets Encrypt
for all nginx servers. If enabled it will install acme-client
tool and prepare
some configuration for the servers. Default: no
.
Use this var to specify the private key, that will be used by acme client to communicate with LetsEncrypt. Default: '''
.
The host name of the server to talk to. Default: acme-v02.api.letsencrypt.org
.
Whether the webroot of all nginx servers should be backed up using tarsnap. Has
to be enabled on the host itself (tarsnap_enabled: yes
). Default:
{{ tarsnap_enabled | default("no") }}
.
The syslogd server nginx should use to write error and access log Default:
{{ syslogd_server | default("localhost") }}
.
If set to yes
if traffic to http(s) ports is forwarded to this jails nginx
server. Default: no
.
If enabled, the default configuration will forward traffic directed to port 80
and 443 of the hosts external interface to this jail. This configuration can be
changed using the nginx_pf_rdrs
variable.
This configures how traffic redirection from host to jail works. The default configuration looks like this.
nginx_pf_rdrs:
- ports:
- 'http'
- 'https'
ext_ip: '{{ host_net_ext_ip }}'
ext_if: '{{ host_net_ext_if }}'
This means that all traffic terminating on host's external interface with external ip for both ports https
and http
will be redirected to port http
of the NGINX running inside the jail.
This variable holds an array of nginx server instances for this jail. You can use this to configure different types of nginx jails, e.g. https terminating proxy, serve multiple static websites, or a php enable website. See example section below.
aliases: ''
basic_auth_enabled: no
force_www: no
https:
enabled: no
letsencrypt_enabled: no
key_file: 'localhost-key.pem'
certbundle_file: 'localhost-certbundle.pem'
dhparam_file: 'localhost-dhparam.pem'
name: 'localhost'
php_fpm_enabled: no
sftp:
user: '{{ server_sftp_user }}'
uuid: '{{ server_sftp_uuid }}'
authorized_keys: '{{ server_sftp_authorized_keys }}'
home: '{{ server_home }}'
port: '{{ server_sftp_port }}'
sftp_enabled: no
webroot: '{{ server_webroot }}'
If the server should handle other request then those directed to server_name
.
Provide list of domain names separated by space. Use default
to create and Nginx default server. Default: ''
.
Set to true
to enable basic auth for this server. You need to provide the htpasswd
file and save it under files {{ server_name }}/htpasswd
.
If the server should redirect to www
domain names. If set to yes
all
requests to name
will be redirected to www subdomain. You also need to add www.name
to aliases
property. Default: no
.
Settings related to SSL/HTTPS.
Set to yes
to enabled SSL/HTTPS for this server. HTTP only request will be redirected to HTTPS.
If set https is enabled for this server and certificates will be created by
Lets Encrypt and acme-client
. You need to set nginx_letsencrypt_enabled
to yes
as well to enable this feature. Default: no
.
The domain name of this server, e.g. example.com
. Default: default
.
PHP related settings
Set to true to install and enable php-fpm
package. If enabled the following
packages listed in nginx_php_fpm_pkgs
will be installed. Default: no
.
Set to off
to disabled fastcgi cache. Default: z_nginx
.
The number of requests each child process should execute before respawning. Default: 1000
.
The max, number of child processes to be created. Default: 5
.
This sets the maximum amount of memory in bytes that a script is allowed to allocate. Default: 128M
.
The maximum size of an uploaded file. Default: 48M
.
Sets max size of post data allowed. Default: 64M
Enable sftp
for this server. Creates an user and adjusts settings as
described below. Default: false
.
Settings used to setup user and configure SSHD to allow access to web server root to upload files.
The sftp user's name. Default: 'sftp_{{ name | truncate(5, True, "") }}'
.
The sftp user's uuid. Default: 5000
.
The user's home directory. sshd
will change root to this diretory. Set the the web server home when unset. Default: '/srv/{{ name }}'
.
The external port which should be redirected to the jail using this role.
Default: 10022
.
The public key which should be used to authenticate the user. Default: '{{ host_sshd_authorized_keys_file }}'
.
Proxy host, that forwards traffic to other external server.
- hosts: all
become: true
tasks:
- import_role:
name: 'JoergFiedler.freebsd-jail-host'
- include_role:
name: 'JoergFiedler.freebsd-jailed-nginx'
vars:
nginx_pf_redirect: true
nginx_letsencrypt_enabled: yes
nginx_servers:
- name: 'test.moumantai.de'
https:
enabled: yes
letsencrypt_enabled: yes
proxy:
host: 'www.freebsd.org'
scheme: 'https'
port: 443
local: no
jail_net_ip: '10.1.0.10'
jail_name: 'nginx'
Nginx server with php-fpm
module and HTTPS.
- hosts: all
become: true
tasks:
- import_role:
name: 'JoergFiedler.freebsd-jail-host'
- include_role:
name: 'JoergFiedler.freebsd-jailed-nginx'
vars:
jail_net_ip: '10.1.0.10'
jail_name: 'nginx'
nginx_pf_redirect: yes
nginx_servers:
- name: 'default'
https:
enabled: yes
php:
fpm_enabled: yes
sftp_enabled: yes
sftp:
authorized_keys: '~/.vagrant.d/insecure_private_key.pub'
BSD
If you like it or do have ideas to improve this project, please open an issue on GitHub. Thanks.