ff-frontend.conf 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. access_log /var/log/nginx/{{ domain }}.access.log;
  31. error_log /var/log/nginx/{{ domain }}.error.log;
  32. {%- if https %}
  33. ssl on;
  34. ssl_certificate /etc/ssl/certs/{{ domain }}.cert.pem;
  35. ssl_certificate_key /etc/ssl/private/{{ domain }}.key.pem;
  36. {%- endif %}
  37. {%- if 'proxy_pass' in config %}
  38. location / {
  39. proxy_pass {{ config.proxy_pass }};
  40. proxy_redirect default;
  41. proxy_set_header Host "{{ host }}";
  42. proxy_set_header X-Forwarded-For $remote_addr;
  43. include /etc/nginx/ffho.d/proxy-headers.conf;
  44. }
  45. {%- elif 'redirect' in config %}
  46. location / {
  47. return 302 {{ config.redirect }};
  48. }
  49. {%- elif 'location' in config %}
  50. {%- for location, loc_conf in config.location.items()|sort %}
  51. location {{ location }} {
  52. {%- if 'proxy_pass' in loc_conf %}
  53. {%- set loc_host = salt['pillar.get']('frontend:' ~ domain ~ ':location:' ~ location ~ ':host', host) %}
  54. proxy_pass {{ loc_conf.proxy_pass }};
  55. proxy_redirect default;
  56. proxy_set_header Host "{{ loc_host }}";
  57. proxy_set_header X-Forwarded-For $remote_addr;
  58. include /etc/nginx/ffho.d/proxy-headers.conf;
  59. {%- elif 'redirect' in loc_conf %}
  60. return 302 {{ loc_conf.redirect }};
  61. {%- endif %}
  62. }
  63. {% endfor %}
  64. {%- endif %}
  65. {%- if acme_thumbprint %}
  66. location ~ "^/\.well-known/acme-challenge/([-_a-zA-Z0-9]+)$" {
  67. default_type text/plain;
  68. return 200 "$1.{{ acme_thumbprint }}";
  69. }
  70. {%- endif %}
  71. }
  72. {%- endfor %}