ff-frontend.conf 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #
  2. # FF Frontend configuration (Salt managed)
  3. #
  4. {%- set acme_thumbprint = salt['pillar.get']('acme:thumbprint', False) %}
  5. {%- for domain, config in pillar.get('frontend', {}).items()|sort if 'file' not in config %}
  6. {%- set https = domain in salt['pillar.get']('cert', {}) and salt['pillar.get']('frontend:' ~ domain ~ ':https', True) %}
  7. {%- set http = salt['pillar.get']('frontend:' ~ domain ~ ':http', not https) %}
  8. {%- set host = salt['pillar.get']('frontend:' ~ domain ~ ':host', domain) %}
  9. #
  10. # {{ domain }}
  11. server {
  12. {%- if http %}
  13. listen 80{% if http == 'default_server' %} default_server{% endif %};
  14. listen [::]:80{% if http == 'default_server' %} default_server{% endif %};
  15. {%- endif %}
  16. {%- if https %}
  17. listen 443{% if https == 'default_server' %} default_server{% endif %};
  18. listen [::]:443{% if https == 'default_server' %} default_server{% endif %};
  19. {%- endif %}
  20. {#- set server_name #}
  21. {%- if 'server_name' in config %}
  22. server_name {{ config.server_name }};
  23. {%- elif 'domains' in config %}
  24. {%- set domains = config.domains %}
  25. {%- do domains.append(domain) %}
  26. server_name ~^({{ domains|join('|') }})$;
  27. {%- else %}
  28. server_name "{{ domain }}";
  29. {%- endif %}
  30. {%- if https %}
  31. ssl on;
  32. ssl_certificate /etc/ssl/certs/{{ domain }}.cert.pem;
  33. ssl_certificate_key /etc/ssl/private/{{ domain }}.key.pem;
  34. {%- endif %}
  35. {%- if 'proxy_pass' in config %}
  36. location / {
  37. proxy_pass {{ config.proxy_pass }};
  38. proxy_redirect default;
  39. proxy_set_header Host "{{ host }}";
  40. proxy_set_header X-Forwarded-For $remote_addr;
  41. }
  42. {%- elif 'redirect' in config %}
  43. location / {
  44. return 302 {{ config.redirect }};
  45. }
  46. {%- elif 'location' in config %}
  47. {%- for location, loc_conf in config.location.items()|sort %}
  48. location {{ location }} {
  49. {%- if 'proxy_pass' in loc_conf %}
  50. {%- set loc_host = salt['pillar.get']('frontend:' ~ domain ~ ':location:' ~ location ~ ':host', host) %}
  51. proxy_pass {{ loc_conf.proxy_pass }};
  52. proxy_redirect default;
  53. proxy_set_header Host "{{ loc_host }}";
  54. proxy_set_header X-Forwarded-For $remote_addr;
  55. {%- elif 'redirect' in loc_conf %}
  56. return 302 {{ loc_conf.redirect }};
  57. {%- endif %}
  58. }
  59. {% endfor %}
  60. {%- endif %}
  61. {%- if acme_thumbprint %}
  62. location ~ "^/\.well-known/acme-challenge/([-_a-zA-Z0-9]+)$" {
  63. default_type text/plain;
  64. return 200 "$1.{{ acme_thumbprint }}";
  65. }
  66. {%- endif %}
  67. }
  68. {%- endfor %}