-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christophe Benz
committed
Oct 29, 2021
1 parent
8a93870
commit ee0dfcd
Showing
14 changed files
with
93 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ all: | |
|
||
# Reverse proxy | ||
|
||
host_name: legislation.demo.openfisca.org | ||
reverse_proxy_host_name: legislation.demo.openfisca.org | ||
|
||
letsencrypt_email: [email protected] | ||
letsencrypt_environment: production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ all: | |
|
||
# Reverse proxy | ||
|
||
host_name: legislation.fr.openfisca.org | ||
reverse_proxy_host_name: legislation.fr.openfisca.org | ||
|
||
letsencrypt_email: [email protected] | ||
letsencrypt_environment: production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
12 changes: 0 additions & 12 deletions
12
ops/ansible/roles/legislation_explorer/templates/nginx/legislation-explorer.conf.j2
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# To activate the Nginx reverse proxy, set `reverse_proxy_host_name` to the host name it will listen to | ||
reverse_proxy_host_name: null | ||
reverse_proxy_base_path: / | ||
|
||
# Optional: SSL certificate | ||
# An SSL certificate is issued from Let's Encrypt if `letsencrypt_email` is defined. | ||
letsencrypt_email: null | ||
letsencrypt_environment: staging # switch to `production` only after testing to avoid reaching your Let's Encrypt quota | ||
|
||
# Fully managed by Ansible, you should not need to edit this unless you have a naming collision | ||
nginx_conf_file_name: "{{ reverse_proxy_host_name }}.conf" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
- name: Install the reverse-proxy | ||
when: reverse_proxy_host_name | ||
block: | ||
- name: Install the Nginx Ubuntu package | ||
ansible.builtin.apt: | ||
install_recommends: no | ||
name: | ||
- nginx | ||
state: present | ||
update_cache: no | ||
|
||
- name: Copy the nginx vhost file to the sites-available directory of Nginx | ||
ansible.builtin.template: | ||
src: legislation-explorer.conf.j2 | ||
dest: "/etc/nginx/sites-available/{{ nginx_conf_file_name }}" | ||
|
||
- name: Link the nginx vhost file to the sites-enabled directory of Nginx | ||
ansible.builtin.file: | ||
src: "/etc/nginx/sites-available/{{ nginx_conf_file_name }}" | ||
dest: "/etc/nginx/sites-enabled/{{ nginx_conf_file_name }}" | ||
state: link | ||
notify: Reload nginx | ||
|
||
- name: Set SSL up | ||
when: letsencrypt_email | ||
block: | ||
- name: Install Certbot and its Nginx plugin | ||
ansible.builtin.apt: | ||
install_recommends: no | ||
name: | ||
- certbot | ||
- python3-certbot-nginx | ||
state: present | ||
update_cache: no | ||
|
||
- name: Use Let's Encrypt staging environment | ||
when: letsencrypt_environment == "staging" | ||
ansible.builtin.set_fact: | ||
certbot_staging_option: "--staging" | ||
|
||
- name: Issue or renew an SSL certificate with Let's Encrypt | ||
ansible.builtin.command: > | ||
certbot | ||
--non-interactive --email {{ letsencrypt_email }} --agree-tos | ||
--nginx --redirect | ||
--cert-name {{ reverse_proxy_host_name }} | ||
--domain {{ reverse_proxy_host_name }} | ||
--keep-until-expiring | ||
{{ certbot_staging_option | default() }} | ||
become_user: root | ||
register: certbot_result | ||
|
||
- name: Enable HTTP/2 | ||
ansible.builtin.lineinfile: | ||
backrefs: yes | ||
line: '\1\2 http2;\3' | ||
path: "/etc/nginx/sites-available/{{ nginx_conf_file_name }}" | ||
regexp: "^(.*)(listen 443 ssl);(.+)$" | ||
notify: Reload nginx | ||
tags: | ||
- http2 |
12 changes: 12 additions & 0 deletions
12
ops/ansible/roles/reverse_proxy/templates/legislation-explorer.conf.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
server { | ||
listen 80; | ||
server_name {{ reverse_proxy_host_name }}; | ||
|
||
access_log /var/log/nginx/{{ reverse_proxy_host_name }}-access.log; | ||
error_log /var/log/nginx/{{ reverse_proxy_host_name }}-error.log; | ||
|
||
location ~ ^{{ reverse_proxy_base_path }}(.*)$ { | ||
proxy_pass http://127.0.0.1:{{ app_port }}/$1; | ||
include /etc/nginx/proxy_params; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
hosts: all | ||
roles: | ||
- legislation_explorer | ||
- reverse_proxy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters