vhosts.j2 2.2 KB

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