mirror of
https://github.com/2martens/cloud-configuration.git
synced 2026-10-17 08:37:56 +02:00
Enable updating nginx configuration after certbot run
This commit is contained in:
@@ -1,5 +1,20 @@
|
|||||||
---
|
---
|
||||||
- name: Add HTTP site
|
- name: Determine if Nginx config already exists
|
||||||
|
ansible.builtin.stat:
|
||||||
|
path: /etc/nginx/sites-available/{{ spring_domain }}.conf
|
||||||
|
register: nginx_site
|
||||||
|
- name: Update Spring nginx site
|
||||||
|
when: nginx_site.stat.exists
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: etc/nginx/sites-available/spring_domain_existing.conf.j2
|
||||||
|
dest: /etc/nginx/sites-available/{{ spring_domain }}.conf
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "644"
|
||||||
|
force: true
|
||||||
|
lstrip_blocks: true
|
||||||
|
- name: Add Spring nginx site
|
||||||
|
when: not nginx_site.stat.exists
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
src: etc/nginx/sites-available/spring_domain.conf.j2
|
src: etc/nginx/sites-available/spring_domain.conf.j2
|
||||||
dest: /etc/nginx/sites-available/{{ spring_domain }}.conf
|
dest: /etc/nginx/sites-available/{{ spring_domain }}.conf
|
||||||
@@ -12,7 +27,8 @@
|
|||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: rm /etc/nginx/sites-enabled/default
|
cmd: rm /etc/nginx/sites-enabled/default
|
||||||
removes: /etc/nginx/sites-enabled/default
|
removes: /etc/nginx/sites-enabled/default
|
||||||
- name: Enable HTTP site
|
- name: Enable Spring nginx site
|
||||||
|
when: not nginx_site.stat.exists
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
cmd: ln -sf /etc/nginx/sites-available/{{ spring_domain }}.conf /etc/nginx/sites-enabled/{{ spring_domain }}.conf
|
cmd: ln -sf /etc/nginx/sites-available/{{ spring_domain }}.conf /etc/nginx/sites-enabled/{{ spring_domain }}.conf
|
||||||
creates: /etc/nginx/sites-enabled/{{ spring_domain }}.conf
|
creates: /etc/nginx/sites-enabled/{{ spring_domain }}.conf
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ server {
|
|||||||
{% for app in spring_apps %}
|
{% for app in spring_apps %}
|
||||||
{% if app.expose %}
|
{% if app.expose %}
|
||||||
location {{ app.path }} {
|
location {{ app.path }} {
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
proxy_pass http://localhost:{{ app.port }};
|
proxy_pass http://localhost:{{ app.port }};
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
server {
|
||||||
|
|
||||||
|
server_name {{ spring_domain }};
|
||||||
|
|
||||||
|
location ^~ /.well-known/acme-challenge/ {
|
||||||
|
default_type "text/plain";
|
||||||
|
}
|
||||||
|
|
||||||
|
{% for app in spring_apps %}
|
||||||
|
{% if app.expose %}
|
||||||
|
location {{ app.path }} {
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_pass http://localhost:{{ app.port }};
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
listen [::]:443 ssl ipv6only=on; # managed by Certbot
|
||||||
|
listen 443 ssl; # managed by Certbot
|
||||||
|
ssl_certificate /etc/letsencrypt/live/{{ spring_domain }}/fullchain.pem; # managed by Certbot
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/{{ spring_domain }}/privkey.pem; # managed by Certbot
|
||||||
|
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
|
||||||
|
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
|
||||||
|
}
|
||||||
|
server {
|
||||||
|
if ($host = {{ spring_domain }}) {
|
||||||
|
return 301 https://$host$request_uri;
|
||||||
|
} # managed by Certbot
|
||||||
|
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
|
||||||
|
server_name {{ spring_domain }};
|
||||||
|
return 404; # managed by Certbot
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user