vhosts.j2 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. {% for x509 in vhosts_x509.results %}
  2. {%- set vhost = x509.vhost -%}
  3. {%- set ssl = vhost.ssl | default(false) -%}
  4. {%- set php_fastcgi = vhost.php_fastcgi | default(false) -%}
  5. {%- set frame_options = vhost.frame_options | default('SAMEORIGIN') -%}
  6. server {
  7. listen
  8. {%- if ssl %}
  9. {{ vhost.listen | default('443') }} ssl
  10. {%- else %}
  11. {{ vhost.listen | default('80') }}
  12. {%- endif -%}
  13. {%- if vhost.default_server | default(false) %}
  14. default_server
  15. {%- endif -%}
  16. ;
  17. {% if vhost.server_name is defined %}
  18. server_name {{ vhost.server_name }};
  19. {% endif %}
  20. {% if ssl %}
  21. ssl_certificate "{{ x509.cert_path }}";
  22. ssl_certificate_key "{{ x509.key_path }}";
  23. {% if vhost.strict_transport_security | default(false) %}
  24. add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; ";
  25. {% endif %}
  26. {% endif %}
  27. {% if vhost.root is defined %}
  28. root {{ vhost.root }};
  29. {% endif %}
  30. {% if vhost.index is defined %}
  31. index {{ vhost.index }};
  32. {% else %}
  33. index {% if php_fastcgi %}index.php {% endif %}index.html;
  34. {% endif %}
  35. {% if vhost.error_page is defined %}
  36. error_page {{ vhost.error_page }};
  37. {% endif %}
  38. {% if vhost.access_log is defined %}
  39. access_log {{ vhost.access_log }};
  40. {% endif %}
  41. {% if vhost.error_log is defined %}
  42. error_log {{ vhost.error_log }} error;
  43. {% endif %}
  44. {% if frame_options %}
  45. add_header X-Frame-Options {{frame_options}};
  46. {% endif %}
  47. {% if vhost.return is defined %}
  48. return {{ vhost.return }};
  49. {% endif %}
  50. {% if php_fastcgi %}
  51. location ~ [^/]\.php(/|$) {
  52. # correctly handle request like /test.php/foo/blah.php or /test.php/
  53. fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  54. # check whether the *.php does indeed exist to prevent nginx
  55. # to feeding PHP FPM non php script file (like uploaded image)
  56. # (if instead of try_files due to nginx bug #321)
  57. if (!-f $document_root$fastcgi_script_name) {
  58. return 404;
  59. }
  60. # Mitigate https://httpoxy.org/ vulnerabilities
  61. fastcgi_param HTTP_PROXY "";
  62. fastcgi_pass unix:/var/run/php5-fpm.sock;
  63. fastcgi_index index.php;
  64. include fastcgi_params;
  65. }
  66. # https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/
  67. {% endif %}
  68. {% if vhost.extra_parameters is defined %}
  69. {{ vhost.extra_parameters|indent(4) }}
  70. {% endif %}
  71. }
  72. {% endfor %}